@param Request        $request
@param RequestHandler $responder Request responder.

@return Promise<\Amp\Http\Server\Response>
553120
public function handleRequest(Request $request, RequestHandler $responder): Promise
    {
        return call(function () use ($request, $responder) {
            $cookie = $request->getCookie($this->cookieName);

            $originalId = $cookie ? $cookie->getValue() : null;
            $session = new Session($this->storage, $originalId);

            $request->setAttribute($this->requestAttribute, $session);

            try {
                $response = yield $responder->handleRequest($request);
            } finally {
                if ($session->isLocked()) {
                    $session->unlock();
                }
            }

            if (!$response instanceof Response) {
                throw new \TypeError("Request handler must resolve to an instance of " . Response::class);
            }

            $id = $session->getId();

            if ($id === null || !$session->isRead()) {
                return $response;
            }

            if ($session->isEmpty()) {
                $attributes = $this->cookieAttributes->withExpiry(
                    new \DateTimeImmutable("@0", new \DateTimeZone("UTC"))
                );

                $response->setCookie(new ResponseCookie($this->cookieName, '', $attributes));

                return $response;
            }

            if ($cookie === null || $cookie->getValue() !== $id) {
                $response->setCookie(new ResponseCookie($this->cookieName, $id, $this->cookieAttributes));
            }

            $cacheControl = $response->getHeaderArray("cache-control");

            if (empty($cacheControl)) {
                $response->setHeader("cache-control", "private");
            } else {
                foreach ($cacheControl as $key => $value) {
                    $tokens = \array_map("trim", \explode(",", $value));
                    $tokens = \array_filter($tokens, function ($token) {
                        return $token !== "public";
                    });

                    if (!\in_array("private", $tokens, true)) {
                        $tokens[] = "private";
                    }

                    $cacheControl[$key] = \implode(",", $tokens);
                }

                $response->setHeader("cache-control", $cacheControl);
            }

            return $response;
        });
    }
1020804
public function resolve(Request $request, Response $response)
    {
        return $response->methodNotAllowed(
                $request->method(),
                $this->allowedMethods
        );
    }
1306643
public static function onRequest($request, $response) {
		$request = new Request($request);
		$request->setCookieHandler([$response, 'cookie']);
		$response = new Response($response);
		Container::getInstance()
			->get(Dispatcher::class)
			->handleRequest($request, $response);
	}
66154
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);

        //Only GET & HEAD request
        if (!in_array($request->getMethod(), ['GET', 'HEAD'], true)) {
            return $response;
        }

        $util = new CacheUtil();

        //Only cacheable responses
        if (!$util->isCacheable($response)) {
            return $response;
        }

        //Check if a lifetime is defined
        $lifetime = $util->getLifetime($response);

        if ($lifetime !== null) {
            return self::withExpires($response, $util, '@'.(time() + $lifetime));
        }

        //Check the content type
        $contentType = $response->getHeaderLine('Content-Type');

        if ($contentType !== '') {
            foreach ($this->expires as $mime => $time) {
                if (stripos($contentType, $mime) !== false) {
                    return self::withExpires($response, $util, $time);
                }
            }
        }

        //Add default value
        return self::withExpires($response, $util, $this->default);
    }
1247287
public function execute(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            return $this->router->start($request, $response);
        } catch (\Exception $e) {
            $this->logger->warning('Unexpected exception: ' . $e->getMessage());
            $this->logger->debug($e->__toString());

            return $response->withStatus(500)
                ->withBody(new StringStream($e->getMessage()));
        }
    }
680749
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $promise = $this->sendAsyncRequest($request);

        return $promise->wait();
    }
297246
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);
        if ($this->onlyPreflight) {
            if ($this->cors->isPreflightRequest('psr-7', $request)) {
                return $this
                    ->handle($request, $response)
                    ->withStatus(204);
            }

            return $response;
        }

        return $this->handle($request, $response);
    }
695841
public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
813177
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $route = $request->getAttribute('_route');
        if( ! $route || ! ($handler instanceof \Sherpa\Kernel\RequestHandler\RequestHandler) ) {
            return $handler->handle($request);
        }
        foreach($route->getMiddlewares() as $m) {
            $handler->getMiddlewareGroup()->addMiddleware($m['middleware'], $m['priority'], $m['before']);
        }

        return $handler->handle($request);
    }
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
884231
private function respond(Request $request, string $buffer): \Generator
    {
        try {
            $method = $request->getMethod();

            if (!\in_array($method, $this->options->getAllowedMethods(), true)) {
                if (!\in_array($method, HttpDriver::KNOWN_METHODS, true)) {
                    $response = yield from $this->makeNotImplementedResponse();
                } else {
                    $response = yield from $this->makeMethodNotAllowedResponse();
                }
            } elseif ($method === "OPTIONS" && $request->getUri()->getPath() === "") {
                $response = $this->makeOptionsResponse();
            } else {
                $response = yield $this->requestHandler->handleRequest(clone $request);

                if (!$response instanceof Response) {
                    throw new \Error("At least one request handler must return an instance of " . Response::class);
                }
            }
        } catch (ClientException $exception) {
            $this->close();
            return;
        } catch (\Throwable $exception) {
            $this->logger->error($exception);
            $response = yield from $this->makeExceptionResponse($request);
        } finally {
            $this->pendingResponses--;
        }

        if ($this->status & self::CLOSED_WR) {
            return; // Client closed before response could be sent.
        }

        $promise = $this->httpDriver->write($request, $response);

        if ($response->isUpgraded()) {
            yield $promise; // Wait on writing response when the response is an upgrade response.
            $this->export($response->getUpgradeCallable(), $buffer);
        }
    }
893333
public function process(RequestInterface $request, RequestHandlerInterface $handler)
    {
        $url = $request->getSequentialParam(1);

        $this->router->route($url, 'execute');

        return $handler->handle($request);
    }
214392
public function handle(Request $request)
    {
        $response = new Response();
        $response = $this->executePassiveActions($request, $response);
        $response = $this->executeAction($request, $response);

        if ($response->isClientError() || $response->isServerError()) {
            return $this->handleError($request, $response);
        }

        return $response;
    }
261021
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);
        $response = $this->responseView($request, $response);

        return $response;
    }
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();
    }
503471
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);

        $this->assertHeadersNotEmitted();
        $this->assertBodyNotEmitted();
        $this->emitStatusLine($response);
        $this->emitHeaders($response);
        $this->emitBody($response);
        $this->closeConnection();

        return $response;
    }
785741
public function process(
        RequestInterface $request,
        ResponseInterface $response,
        DelegateInterface $next = null
    ) {
        try {
            if ($next) {
                return $next->next($request, $response);
            }
            return $response;
        } catch (\Exception $e) {
            return WhoopsRunner::handle($e, $request);
        }
    }