@param ServerRequestInterface $httpRequest
@param RequestConditions      $expectedRequest

@return bool
433445
private function requestUrlMatchesExpectation(ServerRequestInterface $httpRequest, RequestConditions $expectedRequest)
    {
        $inputSource = $this->inputSourceLocator->locate('url');
        $matcher = $this->matcherLocator->locate($expectedRequest->getUrl()->getMatcher()->asString());

        return $matcher->match(
            $inputSource->getValue($httpRequest),
            $expectedRequest->getUrl()->getValue()->asString()
        );
    }
393246
public function handle(ServerRequestInterface $request, Throwable $e, bool $displayErrorDetails): ResponseInterface
    {
        $this->shouldBeVerbose = $displayErrorDetails;

        $this->report($request, $e);

        $formatter = $this->getFilteredFormatter($e, $request);
        $body = $formatter->format($request, $e);

        $statusCode = $this->determineStatusCode($e, $request);
        $contentType = $formatter->contentType();

        $response = $this->createResponse($statusCode, $contentType, $body);

        if ($e instanceof HttpException) {
            $response = $this->injectHeaders($response, $e->getHeaders());
        }

        return $response;
    }
132479
private function isValid(ServerRequestInterface $request): bool
    {
        $method = strtoupper($request->getMethod());

        if (in_array($method, ['GET', 'HEAD', 'CONNECT', 'TRACE', 'OPTIONS'], true)) {
            return true;
        }

        $data = $request->getParsedBody();

        return isset($data[$this->name]) && $data[$this->name] === '';
    }
437156
public function matchRequest(ServerRequest $request)
    {
        return $this->getMatchRoute(
            $request->getMethod(),
            $this->getUrl($request)
        );
    }
911099
protected function _pluginCondition(ServerRequest $request)
    {
        if ($request->getParam('plugin') !== null) {
            return [$this->getAlias() . '.plugin' => $request->getParam('plugin')];
        }

        return [$this->getAlias() . '.plugin IS NULL'];
    }
368275
private function report(ServerRequestInterface $request, Throwable $e): void
    {
        if ($this->shouldntReport($e)) {
            return;
        }

        foreach ($this->reporters as $reporter) {
            if ($reporter->canReport($e)) {
                $reporter->report($request, $e);
            }
        }
    }
791238
private function mustRedirect(ServerRequestInterface $request): bool
    {
        if ($this->redirect === false) {
            return false;
        }

        return !$this->checkHttpsForward || (
            $request->getHeaderLine('X-Forwarded-Proto') !== 'https' &&
            $request->getHeaderLine('X-Forwarded-Port') !== '443'
        );
    }
584978
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $result = $request->getAttribute('routing');

        if (isset($result['error'])) {
            throw HttpErrorException::create($result['error'], [
                'code' => $result['error'],
                'message' => 'Routing not found',
            ]);
        }

        $this->count = 0;
        $this->app->setRequest($request->withoutAttribute('routing'));

        return $this->handle($result['handler'], $result['params']);
    }
487505
private function checkRequest(ServerRequestInterface $request): bool
    {
        if ($request->getParsedBody() && !$this->override) {
            return false;
        }

        if (!in_array($request->getMethod(), $this->methods, true)) {
            return false;
        }

        $contentType = $request->getHeaderLine('Content-Type');

        foreach ($this->contentType as $allowedType) {
            if (stripos($contentType, $allowedType) === 0) {
                return true;
            }
        }

        return false;
    }
1133202
public function processServerRequest($serverRequest)
    {
        $response = $this->processor()->process($serverRequest);

        return $response->asResponseMessage(
            $this->builder->context()->httpContext()
        );
    }
548247
private function detectCharset(ServerRequestInterface $request)
    {
        $accept = $request->getHeaderLine('Accept-Charset');

        return $this->negotiateHeader($accept, new CharsetNegotiator(), $this->charsets);
    }
186921
private function fillWithBodyMatches(Expectation $expectation, ServerRequestInterface $httpRequest, $responseBody)
    {
        if ($this->bodyConditionIsRegex($expectation)) {
            return $this->replaceMatches(
                'body',
                $expectation->getRequest()->getBody()->getValue(),
                $httpRequest->getBody()->__toString(),
                $responseBody
            );
        }

        return $responseBody;
    }
951454
public function callback(ServerRequestInterface $request)
    {
        $response = new Response(200, [
            'Content-Type' => 'text/plain; charset=utf-8',
        ], '');

        return new Promise(function ($resolve, $reject) use (&$request, &$response) {
            try {
                $context = new Context($request, $response);
                $context->setLogger($this->getLogger());

                /**
                 * @var HttpBodyStream $body
                 */
                $body = $request->getBody();
                $body->on('data', function ($data) use (&$request, &$context) {
                    if (!$data) return;
                    $method = $request->getMethod();
                    $contentType = $request->getHeader('Content-Type');
                    if (isset($contentType[0])
                        && (strcasecmp($method, 'POST') === 0 || strcasecmp($method, 'PUT') === 0)
                    ) {
                        if (strpos(strtolower($contentType[0]), 'application/x-www-form-urlencoded') !== false) {
                            parse_str($data, $parsedBody);
                            $request = $request->withParsedBody($parsedBody);
                            $context->setRequest($request);
                        } else if (strpos(strtolower($contentType[0]), 'application/json') !== false) {
                            $parsedBody = json_decode($data, JSON_OBJECT_AS_ARRAY);
                            $request = $request->withParsedBody($parsedBody);
                            $context->setRequest($request);
                        }
                    }
                    $context->setAttribut('httpRawData', $data);
                });
                $body->on('end', function () use (&$context, $resolve) {
                    co(...$this->middlewares)($context);
                    $resolve($context->getReturn());
                });
                $body->on('error', function ($reason) use ($reject) {
                    $reject($reason);
                });
            } catch (\Throwable $exception) {
                // 触发错误异常处理中间件
                $this->onException($exception, $context);
                $rsp = $context->getResponse();
                if ($rsp === $response) {
                    $rsp = $response->withStatus(500);
                    $response->getBody()->write('Internal Server Error');
                }
                $resolve($rsp);
            }
        });
    }
444661
private function httpExceptionResponse(ServerRequestInterface $request, HttpException $exception): ResponseInterface
    {
        if ($request->getHeaderLine('X-Requested-With') !== '') {
            $this->layout = 'layouts/ajax';
        }

        return $this->viewResponse('components/alert-danger', [
            'alert' => $exception->getMessage(),
            'title' => $exception->getMessage(),
        ], $exception->getStatusCode());
    }
1354311
private function detectFromHeader(ServerRequestInterface $request)
    {
        $accept = $request->getHeaderLine('Accept-Language');
        $language = $this->negotiateHeader($accept, new LanguageNegotiator(), $this->languages);

        if (empty($language)) {
            return isset($this->languages[0]) ? $this->languages[0] : '';
        }

        return $language;
    }
294874
protected function beforeHandleRequest(HTTPRequest $request)
    {
        //Set up the internal dependencies (request, response)
        $this->setRequest($request);
        //Push the current controller to protect against weird session issues
        $this->pushCurrent();
        $this->setResponse(new HTTPResponse());
        //kick off the init functionality
        $this->doInit();
    }
1287106
private function isValid(ServerRequestInterface $request)
    {
        $data = $request->getParsedBody();

        //value does not exists
        if (empty($data[$this->inputName])) {
            return false;
        }

        try {
            $time = $this->decrypt($data[$this->inputName]);
        } catch (Exception $e) {
            return false;
        }

        //value is not valid
        if (!is_numeric($time)) {
            return false;
        }

        $now = time();

        //sent from future
        if ($now < $time) {
            return false;
        }

        $diff = $now - $time;

        //check min
        if ($diff < $this->min) {
            return false;
        }

        //check max
        if ($this->max && $diff > $this->max) {
            return false;
        }

        return true;
    }