Renders the HTTP headers - EXCLUDING the status header - of the given request

@param RequestInterface $request
@return string
970977
public static function renderRequestHeaders(RequestInterface $request): string
    {
        $renderedHeaders = '';
        $headers = $request->getHeaders();
        if ($headers instanceof Headers) {
            $renderedHeaders .= $headers->__toString();
        } else {
            foreach (array_keys($headers) as $name) {
                $renderedHeaders .= $request->getHeaderLine($name);
            }
        }

        return $renderedHeaders;
    }
160949
protected function renderHtmlNotFoundOutput(ServerRequestInterface $request)
    {
        $url = (string) $request->getUri();
        $homeUrl = (string)($request->getUri()->withPath('')->withQuery('')->withFragment(''));
        return <<<END
<html>
    <head>
        <title>Page Not Found</title>
        <style>
            body{
                margin:0;
                padding:30px;
                font:14px/1.5 Helvetica,Arial,Verdana,sans-serif;
            }
            h1{
                margin:0;
                font-size:32px;
                font-weight:normal;
                line-height:48px;
            }
            strong{
                display:inline-block;
                width:65px;
            }
        </style>
    </head>
    <body>
        <h1>Page Not Found</h1>
        <p>
            The page you are looking for could not be found: <b>$url</b>
        </p>
        <p>
            Check the address bar
            to ensure your URL is spelled correctly. If all else fails, you can
            visit our home page at the link below.
        </p>
        <a href='$homeUrl'>Visit the Home Page</a>
    </body>
</html>
END;
    }
1121914
protected function doRequest(RequestInterface $request)
    {
        // Create the stream context options array with the required method offset.
        $options = ['method' => $request->getMethod()];

        // Set HTTP Version
        $options['protocol_version'] = $request->getProtocolVersion();

        // If data exists let's encode it and make sure our Content-Type header is set.
        $data = (string) $request->getBody();

        if (isset($data)) {
            // If the data is a scalar value simply add it to the stream context options.
            if (is_scalar($data)) {
                $options['content'] = $data;
            } else // Otherwise we need to encode the value first.
            {
                $options['content'] = http_build_query($data);
            }

            if (!$request->getHeader('Content-Type')) {
                $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
            }

            // Add the relevant headers.
            $request = $request->withHeader('Content-Length', (string) strlen($options['content']));
        }

        // Speed up stream get URL
        // @see http://stackoverflow.com/questions/3629504/php-file-get-contents-very-slow-when-using-full-url
        // @see http://stackoverflow.com/questions/13679976/how-to-speed-up-file-get-contents
        $request = $request->withHeader('Connection', 'Close');

        // Build the headers string for the request.
        if ($headers = $request->getHeaders()) {
            // Add the headers string into the stream context options array.
            $options['header'] = HeaderHelper::toHeaderLine($headers, true);
        }

        // If an explicit timeout is given user it.
        if ($this->getOption('timeout')) {
            $options['timeout'] = (int) $this->getOption('timeout');
        }

        // If an explicit user agent is given use it.
        if ($this->getOption('userAgent')) {
            $options['user_agent'] = $this->getOption('userAgent');
        }

        // Ignore HTTP errors so that we can capture them.
        $options['ignore_errors'] = 1;

        // Follow redirects.
        $options['follow_location'] = (int) $this->getOption('follow_location', 1);

        foreach ((array) $this->getOption('options') as $key => $value) {
            $options[$key] = $value;
        }

        // Create the stream context for the request.
        $context = stream_context_create(['http' => $options]);

        // Capture PHP errors
        $php_errormsg = '';
        $track_errors = ini_get('track_errors');
        ini_set('track_errors', '1');

        $connection = @fopen($request->getRequestTarget(), Stream::MODE_READ_ONLY_FROM_BEGIN, false, $context);

        if (!$connection) {
            if (!$php_errormsg) {
                // Error but nothing from php? Create our own
                $php_errormsg = sprintf('Could not connect to resource: %s', $request->getRequestTarget());
            }

            // Restore error tracking to give control to the exception handler
            ini_set('track_errors', $track_errors);

            throw new \RuntimeException($php_errormsg);
        }

        $stream = new Stream($connection);

        if ($dest = $this->getOption('target_file')) {
            $content = '';
            StreamHelper::copyTo($stream, $dest);
        } else {
            $content = $stream->getContents();
        }

        $metadata = $stream->getMetadata();

        $stream->close();

        if (isset($metadata['wrapper_data']['headers'])) {
            $headers = $metadata['wrapper_data']['headers'];
        } elseif (isset($metadata['wrapper_data'])) {
            $headers = $metadata['wrapper_data'];
        } else {
            $headers = [];
        }

        return $this->getResponse($headers, $content);
    }
325303
public function decorate(RequestInterface $request)
    {
        return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId());
    }
780701
private function detectFromHeader(ServerRequestInterface $request)
    {
        $mimes = \array_column($this->formats, 'mime-type');
        $headers = \array_merge(...$mimes);

        $accept = $request->getHeaderLine('Accept');
        $mime = $this->getBest($accept, $headers);

        if ($mime !== null) {
            foreach ($this->formats as $format => $data) {
                if (\in_array($mime, $data['mime-type'], true)) {
                    return $format;
                }
            }
        }

        return null;
    }
301944
protected function createHeaders(RequestInterface $request, array $options)
	{
		$headers         = [];
		$request_headers = $request->getHeaders();

		foreach ($request_headers as $name => $values) {
			$header = strtoupper($name);

			// cURL does not support 'Expect-Continue', skip all 'EXPECT' headers
			if ($header === 'EXPECT') {
				continue;
			}

			if ($header === 'CONTENT-LENGTH') {
				if (array_key_exists(CURLOPT_POSTFIELDS, $options)) {
					$values = [strlen($options[CURLOPT_POSTFIELDS])];
				}
				// Force content length to '0' if body is empty
				else if (!array_key_exists(CURLOPT_READFUNCTION, $options)) {
					$values = [0];
				}
			}

			foreach ($values as $value) {
				$headers[] = $name.': '.$value;
			}
		}

		// Although cURL does not support 'Expect-Continue', it adds the 'Expect'
		// header by default, so we need to force 'Expect' to empty.
		$headers[] = 'Expect:';

		return $headers;
	}
364042
public function onRequest( RequestInterface $request ) {
        $localizedUri = Uri::withQueryValue( $request->getUri(), 'lang', $this->getEndpoint()->getLang() );
        return $request->withUri($localizedUri);
    }
1137072
public static function requestToString(RequestInterface $request): string
    {
        $httpMethod = $request->getMethod();
        if (empty($httpMethod)) {
            throw new \UnexpectedValueException('Object can not be serialized because HTTP method is empty');
        }
        $headers = self::serializeHeaders($request->getHeaders());
        $body = (string) $request->getBody();
        $format = '%s %s HTTP/%s%s%s';
        if (! empty($headers)) {
            $headers = self::EOL . $headers;
        }
        if (! empty($body)) {
            $headers .= self::EOL . self::EOL;
        }

        return sprintf(
            $format,
            $httpMethod,
            $request->getRequestTarget(),
            $request->getProtocolVersion(),
            $headers,
            $body
        );
    }
311684
public function processRequest(RequestInterface $request)
    {
        $this->response = $this->communicator->getResponse($request);

        return $this->response;
    }
304398
public function getContentType(RequestInterface $request): string
    {
        try {
            $template = [
                self::CONTENT_TYPE_HTML => XHTMLTemplate::class,
                self::CONTENT_TYPE_JSON => JSONTemplate::class,
                self::CONTENT_TYPE_XML => XMLTemplate::class
            ];
            foreach (explode(",", $request->getHeaderLine(Request::HEADER_ACCEPT)) as $key) {
                if (array_key_exists($key, $template)) {
                    $this->attach(new $template[$key]);
                    return $key . "; charset=utf-8";
                }
            }
        } catch (BadMethodCallException $e) {
        }
        throw new ViewException(
            "Can't get content type in " . static::class
            . " for \"" . $request->getAttribute("action") . "\" action");
    }
69287
private function appendHeaders(RequestInterface $request)
    {
        $headers = $this->auth->getHeaders();
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }
        return $request;
    }
311393
public function handle(RequestInterface $request)
    {
        $response = $request->send();
        $headers = $response->getHeaders()->getAll();
        $body = $response->getBody(true);
        $statusCode = $response->getStatusCode();

        $symfonyHeaders = array();

        foreach ($headers as $keys) {
            /**
             * Transfer-Encoding type chunked is not suported by symfony response
             */
            if($keys->getName() == "Transfer-Encoding" && $keys->__toString() === 'chunked'){
                continue;
            }
            $symfonyHeaders[$keys->getName()] = $keys->__toString();
        }

        return new Response($body,$statusCode,$symfonyHeaders);
    }
259623
public function handle(RequestInterface $request): RequestInterface
    {
        return
            $request->withHeader(
                'Authorization',
                sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
            );
    }
157997
protected function getParsedResponse(RequestInterface $request): string
    {
        $response = $this->getHttpClient()->sendRequest($request);

        $statusCode = $response->getStatusCode();
        if (401 === $statusCode || 403 === $statusCode) {
            throw new InvalidCredentials();
        } elseif (429 === $statusCode) {
            throw new QuotaExceeded();
        } elseif ($statusCode >= 300) {
            throw InvalidServerResponse::create((string) $request->getUri(), $statusCode);
        }

        $body = (string) $response->getBody();
        if (empty($body)) {
            throw InvalidServerResponse::emptyResponse((string) $request->getUri());
        }

        return $body;
    }
1267870
private function getHttpResponse(RequestInterface $request): ?ResponseInterface
    {
        try {
            return $this->httpClient->send($request);
        } catch (TooManyRedirectsException $tooManyRedirectsException) {
            return $this->httpHistoryContainer->getLastResponse();
        } catch (BadResponseException $badResponseException) {
            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $badResponseException->getResponse();
            }

            return $this->getHttpResponse($request);
        } catch (HttpConnectException $connectException) {
            throw $connectException;
        } catch (RequestException $requestException) {
            if ($this->isCurlException($requestException)) {
                throw new HttpConnectException(
                    $requestException->getMessage(),
                    $requestException->getRequest(),
                    $requestException->getPrevious()
                );
            }

            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $requestException->getResponse();
            }

            return $this->getHttpResponse($request);
        }
    }
840054
public static function serialize(RequestInterface $request): string
    {
        return self::requestLine($request).self::headers($request).$request->getBody();
    }
787639
private static function compareHeaderUrl(RequestInterface $request, string $headerName): bool
    {
        $headerValue = $request->getHeader($headerName);
        if ($headerValue === null) {
            // Header value not present.
            return true;
        }

        $headerUrl = Url::tryParse($headerValue);
        if ($headerUrl === null) {
            // Header value is not a valid url.
            return false;
        }

        return $headerUrl->getHost()->equals($request->getUrl()->getHost());
    }