处理请求头

@param  \One\Protocol\Contracts\Request  $request
@param  \One\Protocol\Contracts\Response $response

@return \One\Protocol\Contracts\Response
482878
protected function handleRequestHeader(Request $request, Response $response): Response
    {
        // 处理 No-Cache
        if ($request->header('Cache-Control') === 'no-cache') {
            $response = $response->withHeader('Cache-Control', [
                'no-store',
                'no-cache',
                'must-revalidate'
            ]);
        }

        // 处理 Gzip 请求
        // 不知道为什么，老是出错，还需要再查查
        // https://blog.csdn.net/cs958903980/article/details/76890034?locationNum=6&fps=1
        //
        // $encoding = $request->getHeaderLine('Accept-Encoding');

        // if (! empty($encoding)) {
        //     $negotiator = new EncodingNegotiator;
        //     $preferred = $negotiator->getBest($encoding, ['gzip']);

        //     if (! empty($preferred)) {
        //         $response = $response->withHeader('Content-Encoding', 'gzip');
        //         $response->setGzip(1);
        //     }
        //     unset($negotiator, $preferred);
        // }
        // unset($encoding);

        return $response;
    }
1007273
public static function respond(Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }
1130948
public function call(Request $request, Response $response) : Response {

		return call_user_func($this->callable, $request, $response, $this->slugs);

	}
910027
public function handleRequest(Request $request, Response $response) {
		if ($this->static_enable) {
			$request->uri = $request->server['request_uri'];
			$uri = $request->server['request_uri'];
			if (strpos($uri, $this->static_prefix) === 0) {
				$uri = substr($uri, strlen($this->static_prefix));
			}
			$path = realpath($this->static_dir . $uri);
			if ($path !== false && strpos($path, $this->static_dir) === 0) {
				if ($this->executeInterceptor('before', $request, $response) !== null) {
					$request->end();
					$response->end();
					unset($request, $response);
					return;
				}
				$response->mimeType(pathinfo($path, PATHINFO_EXTENSION));
				$response->sendfile($path);
				$this->executeInterceptor('after', $request, $response);
				$request->end();
				$response->end();
				unset($request, $response);
				return;
			}
		}
		$this->router->parse($request);
		if ($this->executeInterceptor('before', $request, $response) !== null) {
			$request->end();
			$response->end();
			unset($request, $response);
			return;
		}
		$this->dispatch($request, $response);
	}
405869
public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
    {
        $responseAge = $response->calculateAge();
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');

        // Check the request's max-age header against the age of the response
        if ($reqc && $reqc->hasDirective('max-age') &&
            $responseAge > $reqc->getDirective('max-age')) {
            return false;
        }

        // Check the response's max-age header
        if ($response->isFresh() === false) {
            $maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
            if (null !== $maxStale) {
                if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
                    return false;
                }
            } elseif ($resc && $resc->hasDirective('max-age')
                && $responseAge > $resc->getDirective('max-age')
            ) {
                return false;
            }
        }

        if ($this->revalidation->shouldRevalidate($request, $response)) {
            try {
                return $this->revalidation->revalidate($request, $response);
            } catch (CurlException $e) {
                $request->getParams()->set('cache.hit', 'error');
                return $this->canResponseSatisfyFailedRequest($request, $response);
            }
        }

        return true;
    }
708198
public function resolve(Request $request, Response $response)
    {
        $allowedMethods = $this->matchingRoutes->allowedMethods();
        if (!in_array(Http::OPTIONS, $allowedMethods)) {
            $allowedMethods[] = Http::OPTIONS;
        }

        $response->addHeader('Allow', join(', ', $allowedMethods))
                ->addHeader(
                        'Access-Control-Allow-Methods',
                        join(', ', $allowedMethods)
                );
    }
474654
public function execute(\Owl\Http\Request $request, \Owl\Http\Response $response)
    {
        if ($router = $this->getDelegateRouter($request)) {
            return $router->execute($request, $response);
        }

        try {
            if (!$handlers = $this->getMiddlewareHandlers($request)) {
                $this->respond($request, $response);
            } else {
                $handlers[] = function ($request, $response) {
                    $this->respond($request, $response);

                    yield true;
                };

                $this->middleware->execute([$request, $response], $handlers);
            }
        } catch (\Exception $exception) {
            if ($this->exception_handler) {
                call_user_func($this->exception_handler, $exception, $request, $response);
            } else {
                throw $exception;
            }
        } catch (\Throwable $error) {
            if ($this->exception_handler) {
                call_user_func($this->exception_handler, $error, $request, $response);
            } else {
                throw $error;
            }
        }

        return $response;
    }
164591
protected function nonXhrJavascriptResponse($request, $response)
    {
        return ($request->getFormat($response->headers->get('Content-Type')) === 'js' &&
            ! $request->ajax()
        );
    }
875650
public function notFound(Request $request, Response $response)
    {
        $handler = $this->container->get('notFoundHandler');

        return $handler($request, $response);
    }
201152
public function dispatch(Request $request, Response $response) {
		$module = ucfirst($request->module);
		$controller = ucfirst($request->controller);
		$action = ucfirst($request->action);
		$response->setTemplate($controller . '/' . $action);
		$response->setTemplatePath(APP_PATH . 'Module/' . $module . '/View/');
		if (!empty($request->extension)) {
			$response->mimeType($request->extension);
		}
		try {
			$code = self::isValid($module, $controller, $action);
			if ($code === self::ROUTE_VALID) {
				$className = EntryUtil::controller($module, $controller);
				$clazz = Container::getInstance()->get($className);
				$actionName = $action . 'Action';
				$result = $clazz->$actionName($request, $response);
				if ($result !== null) {
					$response->result = $result;
				}
			} else {
				// Not found
				$request->status = $code;
			}
		} catch (\Throwable $e) {
			$request->status = $e;
		}
		$this->executeInterceptor('after', $request, $response);
		$request->end();
		$response->end();
		unset($request, $response);
	}
485733
public function load(Request $request, Response $response) {
        //render the key
        $key = md5(uniqid());
        if($request->hasSession('csrf')) {
            $key = $request->getSession('csrf');
        }

        $request->setSession('csrf', $key);
        $response->setResults('csrf', $key);

        return $this;
    }
874128
protected function doRequest(Request $request)
    {

        $this->client->send($request, $response = new Response());

        return $response;
    }
1290348
protected function setUriHeader(Response $response, Request $request)
    {
        $response->header('X-PJAX-URL', $request->getRequestUri());

        return $this;
    }
416000
public function makeResponse(Request $request, Response $response, Responder $responder): Response
    {
        return $responder(
            $request,
            $response,
            new Payload(
                $this->getCode(),
                '',
                $this->getMessage()
            )
        );
    }
969658
public function response($response, $context = null)
    {
        $responseMessage = $response->asResponseMessage($context);
        $this->responseMessage($responseMessage);
    }
428053
private function executePassiveActions(Request $request, Response $response): Response
    {
        foreach ($this->getRouter()->getConfiguration()->getPassiveActions() as $action => $whitelist) {
            $activeAction = $this->getRouter()->getActionAlias($request);

            if (!in_array($activeAction, $whitelist) && !in_array('all', $whitelist)) {
                continue;
            }

            if (in_array('-' . $activeAction, $whitelist) && in_array('all', $whitelist)) {
                continue;
            }

            $route = $this->getRouter()->getAliasedRoute($action, [], Router::PASSIVE_ACTION);

            if (!method_exists($route->getController(), $route->getAction())) {
                throw new ActionNotFoundException($action . ' passive action is present in registry, but can\'t be found or is improperly configured.');
            }

            $controllerName = $route->getController();
            $controller = new $controllerName($this->drivers, $request, $response);
            $response = $controller->{$route->getAction()}(...$route->getActionParams());
        }

        return $response;
    }
1351086
public function handleHttpResponse(Response $response)
    {
        if ($this->newFormatModeEnabled) {
            $newResponse = $this->newFormattingService->formatResponse($response->getRaw());

            if ($newResponse->hasError()) {
                $error = $newResponse->getError();
                throw new Neo4jException(sprintf(
                    $error->getCode(),
                    $error->getMessage(),
                    Neo4jException::fromCode($error->getCode())
                ));
            }

            return $newResponse;
        }

        $this->checkResponseErrors($response->getBody());
        if ($this->autoFormatResponse) {
            $formatted = $this->formatResponse($response->getBody());
            $response->setResult($formatted->getResult());
            $response->setRows($formatted->geRows());
        }

        return $response;
    }