Collect request information when not already done by the HTTP client. This happens when using the CachePlugin
and the cache is hit without re-validation.

@param RequestInterface $request
@param Stack|null       $stack
195252
private function collectRequestInformation(RequestInterface $request, Stack $stack = null)
    {
        if (empty($stack->getRequestTarget())) {
            $stack->setRequestTarget($request->getRequestTarget());
        }
        if (empty($stack->getRequestMethod())) {
            $stack->setRequestMethod($request->getMethod());
        }
        if (empty($stack->getRequestScheme())) {
            $stack->setRequestScheme($request->getUri()->getScheme());
        }
        if (empty($stack->getRequestHost())) {
            $stack->setRequestHost($request->getUri()->getHost());
        }
        if (empty($stack->getClientRequest())) {
            $stack->setClientRequest($this->formatter->formatRequest($request));
        }
        if (empty($stack->getCurlCommand())) {
            $stack->setCurlCommand($this->formatter->formatAsCurlCommand($request));
        }
    }
69287
private function appendHeaders(RequestInterface $request)
    {
        $headers = $this->auth->getHeaders();
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }
        return $request;
    }
245600
private function doSearch(RequestInterface $request)
    {
        $searchRequest = [
            'index' => $request->getIndex(),
            'type'  => $request->getType(),
            'body'  => $this->requestMapper->buildSearchRequest($request),
        ];

        return $this->client->search($searchRequest);
    }
1162437
public function sendRequest(RequestInterface $request)
    {
        if (isset($this->promises[$request->getRequestId()])) {
            return promise\reject(new ClientException("ID {$request->getRequestId()} already in use"));
        }
        $this->responseBuilders[$request->getRequestId()] = new ResponseParser($request->getRequestId());
        $this->promises[$request->getRequestId()] = new Deferred();
        foreach ($request->toRecords() as $record) {
            $this->connector->write($record->encode());
        }

        return $this->promises[$request->getRequestId()]->promise();
    }
503097
public static function run(array $stack, ServerRequestInterface $request = null): ResponseInterface
    {
        if ($request === null) {
            $request = Factory::createServerRequest('GET', '/');
        }

        return (new static($stack))->dispatch($request);
    }
128866
private function handleRequest(RequestInterface $request, ResponseInterface $response): void
    {
        foreach ($this->routes as $route) {
            $routeMatch = $route->matches($request);

            if ($routeMatch === null) {
                continue;
            }

            $controllerClass = $routeMatch->getControllerClassName();
            $controller = new $controllerClass();

            /** @var ControllerInterface $controller */
            $controller->processRequest($this, $request, $response, $routeMatch->getAction(), $routeMatch->getParameters());

            return;
        }

        $response->setStatusCode(new StatusCode(StatusCode::NOT_FOUND));
    }
102760
private function applyHeaders(RequestInterface $request)
    {
        $headers = [
            'User-Agent' => 'gcloud-php/' . $this->componentVersion,
            'x-goog-api-client' => 'gl-php/' . PHP_VERSION . ' gccl/' . $this->componentVersion,
        ];

        if ($this->shouldSignRequest) {
            $headers['Authorization'] = 'Bearer ' . $this->getToken();
        }

        return Psr7\modify_request($request, ['set_headers' => $headers]);
    }
416574
protected function onFailure(RequestInterface $request)
    {
        return function ($reason) use ($request) {

            // Only log a rejected requests if it hasn't already been logged
            $this->log($request, null, $reason);

            return Promise\rejection_for($reason);
        };
    }
526415
protected function log(RequestInterface $request, $delay)
    {
        if (isset($this->logger)) {
            $level   = $this->getLogLevel($request);
            $message = $this->getLogMessage($request, $delay);
            $context = compact('request', 'delay');

            $this->logger->log($level, $message, $context);
        }
    }
293476
private function onBefore(RequestInterface $request)
    {
        $headers = $this->createHeaders($request);
        foreach ($headers as $headerKey => $headerValue) {
            $request = $request->withHeader($headerKey, $headerValue);
        }

        return $request;
    }
1089221
public function receive(DispatcherRequestInterface $request)
    {
        //Set the headers
        $headers = array();
        foreach ($_SERVER as $key => $value)
        {
            if ($value && strpos($key, 'HTTP_') === 0)
            {
                // Cookies are handled using the $_COOKIE superglobal
                if (strpos($key, 'HTTP_COOKIE') === 0) {
                    continue;
                }

                $headers[substr($key, 5)] = $value;
            }
            elseif ($value && strpos($key, 'CONTENT_') === 0)
            {
                $name = substr($key, 8); // Content-
                $name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name)));

                $headers[$name] = $value;
            }
        }

        $request->getHeaders()->add($headers);
    }
1051768
public function containsRequest(RequestInterface $request)
    {
        return in_array($request, $this->failedRequests, true) || in_array($request, $this->successfulRequests, true);
    }
818123
private function chooseHttpClient(RequestInterface $request)
    {
        foreach ($this->clients as $client) {
            if ($client['matcher']->matches($request)) {
                return $client['client'];
            }
        }

        throw new HttpClientNoMatchException('No client found for the specified request', $request);
    }
429242
protected function getMockHeadersForRequest(RequestInterface $request): array
    {
        try {
            $file = $this->getMockFilePathForRequest($request, self::TYPE_HEADERS);

            return json_decode(file_get_contents($file), true);
        } catch (MockNotFoundException $e) {
            return [];
        }
    }
1366012
public function send(RequestInterface $request)
    {
        $this->logger->info('request: ' . get_class($request), $this->generateLogRequestData($request));

        try {
            $timeTaken = microtime(true);
            $response = $this->client->send($request);

            $this->logger->debug(
                'time taken: ' .
                (microtime(true) - $timeTaken) .
                's (' . get_class($request) . ')'
            );

            $this->logger->debug('response: ' . get_class($response), $this->generateLogResponseData($response));

            return $response;
        } catch (ClientException $exception) {
            $this->logger->error(
                $exception->getMessage(),
                array(
                    'code' => $exception->getCode(),
                    'file' => $exception->getFile(),
                    'line' => $exception->getLine(),
                    'trace' => $exception->getTrace(),
                    'message' => $exception->getMessage(),

                )
            );

            throw $exception;
        }
    }
288863
public function dispatch(RequestInterface $request)
    {
        if (!$request->getParam('section')) {
            $request->setParam('section', $this->configStructure->getFirstSection()->getId());
        }

        return parent::dispatch($request);
    }
560183
public function setLastRequestTime(RequestInterface $request)
    {
        $route = $this->getRoute($request);

        if (!isset($this->routes[$route])) {
            $this->routes[$route] = [];
        }

        $this->routes[$route]['lastRequest'] = $this->getRequestTime($request);
    }