Adds the default context options to the stream context options

@param RequestInterface $request Request
354356
protected function addDefaultContextOptions(RequestInterface $request)
    {
        $this->setContextValue('http', 'method', $request->getMethod());
        $this->setContextValue('http', 'header', $request->getHeaderLines());
        // Force 1.0 for now until PHP fully support chunked transfer-encoding decoding
        $this->setContextValue('http', 'protocol_version', '1.0');
        $this->setContextValue('http', 'ignore_errors', true);
    }
245600
private function doSearch(RequestInterface $request)
    {
        $searchRequest = [
            'index' => $request->getIndex(),
            'type'  => $request->getType(),
            'body'  => $this->requestMapper->buildSearchRequest($request),
        ];

        return $this->client->search($searchRequest);
    }
1098211
protected function addSslOptions(RequestInterface $request)
    {
        if ($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER)) {
            $this->setContextValue('ssl', 'verify_peer', true, true);
            if ($cafile = $request->getCurlOptions()->get(CURLOPT_CAINFO)) {
                $this->setContextValue('ssl', 'cafile', $cafile, true);
            }
        } else {
            $this->setContextValue('ssl', 'verify_peer', false, true);
        }
    }
228929
protected function preparePutRequest(RequestInterface $request, $data)
    {
        $request->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
        if ($data !== null) {
            $request->setOption(CURLOPT_POSTFIELDS, $data);
        }
    }
1102872
private function deEncodeRequestUrl(RequestInterface $request)
    {
        $query = $request->getUri()->getQuery();
        $decodedQuery = rawurldecode($query);

        $request->getUri()->withQuery($decodedQuery);

        return $request;
    }
695484
public static function setRequest(RequestInterface $request)
    {
        $coroutineId = self::getCoroutineId();
        self::$context[$coroutineId][self::REQUEST_KEY] = $request;
    }
690485
protected function _makeOptions(ApiRequestInterface $request)
  {
    $headers = $options = [];

    if($request->getVerb() == HttpVerb::POST)
    {
      $options['json'] = $request->getPostData();
    }

    if($this->_accessToken !== null)
    {
      $headers['Authorization'] = 'Bearer ' . $this->_accessToken;
    }

    if($this->_orgFid !== null)
    {
      $headers['X-Fortifi-Org'] = $this->_orgFid;
    }

    if($this->_disableNesting)
    {
      $headers['Disable-Nesting'] = "true";
    }

    if($this->_disableLogging)
    {
      $headers['Disable-Logging'] = "true";
    }

    if($this->_shortNesting)
    {
      $headers['Short-Nesting'] = "true";
    }

    if(!empty($headers))
    {
      $options['headers'] = $headers;
    }

    return $options;
  }
259623
public function handle(RequestInterface $request): RequestInterface
    {
        return
            $request->withHeader(
                'Authorization',
                sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
            );
    }
320176
protected function dispatchOnRequest(RequestInterface $request): RequestInterface
    {
        $requestEvent = new RequestEvent($request);
        $this->dispatcher->dispatch($this->requestEvent, $requestEvent);

        return $requestEvent->getRequest();
    }
193555
protected function setDataFromRequest(RequestInterface $request)
    {
        $keys = $this->validDataFromRequest();
        $data = $request->getParams($keys);

        if (isset($data['obj_type'])) {
            $this->objType = filter_var($data['obj_type'], FILTER_SANITIZE_STRING);
        }

        if (isset($data['obj_id'])) {
            $this->objId = filter_var($data['obj_id'], FILTER_SANITIZE_STRING);
        }

        if (isset($data['property'])) {
            $this->propertyIdent = filter_var($data['property'], FILTER_SANITIZE_STRING);
        }

        if (isset($data['assets'])) {
            $this->showAssets = !!$data['assets'];
        }

        if (isset($data['callback'])) {
            $this->callbackIdent = filter_var($data['callback'], FILTER_SANITIZE_STRING);
        }

        if (isset($this->elfinderConfig['translations'])) {
            $this->setLocalizations(array_replace_recursive(
                $this->defaultLocalizations(),
                $this->elfinderConfig['translations']
            ));
        }

        return true;
    }
97664
protected function addProxyOptions(RequestInterface $request)
    {
        if ($proxy = $request->getCurlOptions()->get(CURLOPT_PROXY)) {
            $this->setContextValue('http', 'proxy', $proxy);
        }
    }
805441
private function setBodyCurlOpt(RequestInterface $Request) : void
    {

        /*
         * Some HTTP methods cannot have payload:
         *
         * - GET — cURL will automatically change method to PUT or POST if we set CURLOPT_UPLOAD or
         *   CURLOPT_POSTFIELDS.
         * - HEAD — cURL treats HEAD as GET request with a same restrictions.
         * - TRACE — According to RFC7231: a client MUST NOT send a message body in a TRACE request.
         */
        if(!in_array($Request->getMethod(), [Constant::METHOD_GET, Constant::METHOD_HEAD, Constant::METHOD_TRACE], true)){
            $Body       = $Request->getBody();
            $body_size  = $Body->getSize();
            if($body_size !== 0){
                if($Body->isSeekable()){
                    $Body->rewind();
                }

                // Message has non empty body.
                if(null === $body_size || $body_size > 1024 * 1024){
                    // Avoid full loading large or unknown size body into memory
                    $this->option[CURLOPT_UPLOAD] = true;
                    if(null !== $body_size){
                        $this->option[CURLOPT_INFILESIZE] = $body_size;
                    }
                    $this->option[CURLOPT_READFUNCTION] = function($ch, $fd, $length)use($Body){
                        return $Body->read($length);
                    };
                }else{
                    // Small body can be loaded into memory
                    $this->option[CURLOPT_POSTFIELDS] = (string) $Body;
                }
            }
        }

        if($Request->getMethod() === Constant::METHOD_HEAD){
            // This will set HTTP method to "HEAD".
            $this->option[CURLOPT_NOBODY] = true;
        }
    }
977926
private function normalizeRequest(RequestInterface $request): RequestInterface
    {
        $uri = $request->getUri();
        $updated = false;

        $normalizedPath = preg_replace('~/{2,}~', '/', $uri->getPath());

        $normalizedPath = preg_replace('~/\.(/|$)~', '/', $normalizedPath);
        do {
            $normalizedPath = preg_replace('~/[^/]+(?<!\.\.)/+\.\.(/|$)~', '/', $normalizedPath, 1, $count);
        } while ($count);

        $normalizedPath = $this->decodePercentEncoding($normalizedPath);

        if ($uri->getPath() !== $normalizedPath) {
            $uri = $uri->withPath($normalizedPath);
            $updated = true;
        }

        $normalizedQuery = $this->decodePercentEncoding($uri->getQuery());

        if ($uri->getQuery() !== $normalizedQuery) {
            $uri = $uri->withQuery($normalizedQuery);
            $updated = true;
        }

        if ($updated) {
            return $request->withUri($uri);
        }

        return $request;
    }
1072473
private function createHttpRequest(RequestInterface $request)
    {
        // Handle authentication first
        if ($this->authenticationMethod) {
            $request = $this->authenticationMethod->authorizeRequest($this, $request);
        }
        
        // The URL
        $url = ltrim(trim($request->getUrl()), '/');
        
        // Handle templated URLs
        if ($urlVariables = $request->getUrlVariables()) {
            $url = (new UriTemplate())->expand($url, $urlVariables);
        }
        
        // Headers
        $headers = [];
        $headersToAdd = $request->getHeaders();
        
        // The message body
        $body = null;
        if ($messageBody = $request->getMessageBody()) {
            $headers['Content-Type'] = $messageBody->getContentType();
            $headers['Content-Length'] = $messageBody->getContentLength();
            $body = $messageBody->getContent();
        }
        
        // Accept hal+json response
        if ($this->profile) {
            $headers['Accept'] = 'application/hal+json; profile="' . $this->profile . '"';
        } else {
            $headers['Accept'] = 'application/json';
        }
        
        // Prepare the Guzzle request
        if (Misc::isGuzzle6()) {
            // Guzzle 6
            $httpRequest = new \GuzzleHttp\Psr7\Request(
                $request->getMethod(),
                $url,
                array_merge($headers, $headersToAdd),
                $body ? \GuzzleHttp\Psr7\stream_for($body) : null
            );
        } else {
            // Guzzle 5.3
            $httpRequest = $this->client->createRequest($request->getMethod(), $url, ['exceptions' => false]);
            
            // verify option for HTTPS requests if needed
            if (($verify = Misc::verify($url, __DIR__ . '/../CA/')) !== null) {
                $httpRequest->getConfig()->set('verify', $verify);
            }
            
            foreach ($headers as $key => $value) {
                $httpRequest->setHeader($key, $value);
            }
            
            foreach ($headersToAdd as $key => $value) {
                $httpRequest->setHeader($key, $value);
            }
            
            if ($body) {
                $httpRequest->setBody(\GuzzleHttp\Stream\Stream::factory($body));
            }
        }
        
        return $httpRequest;
    }
15949
protected function addDefaultParameters(&$request)
	{
		$defaultParameters = array(
			'all'=>1,
			'dir'=>'ASC',
			'start'=>0,
			'limit'=>999999999);

		foreach ($defaultParameters as $name=> $value)
			$request->getPost()->set($name, $value);
	}
288863
public function dispatch(RequestInterface $request)
    {
        if (!$request->getParam('section')) {
            $request->setParam('section', $this->configStructure->getFirstSection()->getId());
        }

        return parent::dispatch($request);
    }
1175036
protected function setDataFromRequest(RequestInterface $request)
    {
        $keys = $this->validDataFromRequest();
        $data = $request->getParams($keys);
        $this->mergeData($data);

        return $this;
    }