@param Request $request
@param SymfonyResponse $response
@param ResponseModelInterface $responseModel

@return SymfonyResponse
189044
protected function createSerializedResponse(
        Request $request,
        SymfonyResponse $response,
        ResponseModelInterface $responseModel
    ) {
        try {
            $response = $this->serialize($request, $response, $responseModel);
        } catch (\Exception $e) {
            $response = new SymfonyJsonResponse(
                [
                    'error' => [
                        'code' => Error::CODE_SERIALIZE,
                        'message' => $e->getMessage(),
                    ],
                ]
            );
        }

        return $response;
    }
463200
public function executeFilters(Request $request, Response $response)
    {
        $middlewares = $this->filterMiddleware(Filter::class);

        foreach ($middlewares as $middleware) {
            if (($returnResponse = $middleware->doFilter($request, $response)) !== null) {
                return $returnResponse;
            }
            unset($returnResponse);
        }

        unset($middlewares);
    }
250949
public function parse( Request $request, Response $response )
    {
        $this->request  = $request;
        $this->response = $response;

        $response->getHeaders()
                 ->addHeaderLine( 'Content-Type', static::$responseMime .
                                  '; charset=utf-8' );

        $accept = $request->getHeader( 'Accept' );

        if ( empty( $accept ) )
        {
            return self::INVALID_REQUEST;
        }

        $requestMimes = implode( '|', array(
            static::$requestMime,
            preg_quote( '*/*', '#' ),
        ) );

        foreach ( explode( ',', $accept->getFieldValue() ) as $acceptType )
        {
            if ( preg_match( '#^(' . $requestMimes . ')(;.*)?$#',
                 trim( $acceptType ) ) )
            {
                return null;
            }
        }

        return self::INVALID_REQUEST;
    }
1197861
protected function setUriHeader(Request $request, Response $response)
    {
        $response->headers->set('X-PJAX-URL', $request->getUrl());

        return $this;
    }
890708
private function responseView(ServerRequestInterface $request, ResponseInterface $response)
    {
        $ctx   = Context::mustGet();
        $views = ViewRegister::getViews();

        // the info of view model
        $controllerClass  = $ctx->get('controllerClass');
        $controllerAction = $ctx->get('controllerAction');

        $actionId = $controllerClass . '@' . $controllerAction;
        if (!isset($views[$actionId])) {
            return $response;
        }

        // Get layout and template
        [$layout, $template] = $views[$actionId];

        // accept and the of response
        $accepts       = $request->getHeader('accept');
        $currentAccept = \current($accepts);

        /* @var \Swoft\Http\Message\Response $response */
        $responseAttribute = AttributeEnum::RESPONSE_ATTRIBUTE;

        $data = $response->getAttribute($responseAttribute);

        // the condition of view
        $isTextHtml = !empty($currentAccept) && $response->isMatchAccept($currentAccept, 'text/html');
        $isTemplate = $controllerClass && $response->isArrayable($data) && $template;

        // show view
        if ($isTextHtml && $isTemplate) {
            if ($data instanceof Arrayable) {
                $data = $data->toArray();
            }

            /* @var \Swoft\View\Renderer $view */
            $view     = \Swoft::getBean('view');
            $content  = $view->render($template, $data, $layout);
            $response = $response
                ->withContent($content)
                ->withAttribute($responseAttribute, null)
                ->withoutHeader('Content-Type')->withAddedHeader('Content-Type', 'text/html');
        }

        return $response;
    }
530325
public function bind(Request $request = null, AbstractResponse $response = null)
    {
        // Keep references
        $this->request  = $request  ?: $this->request;
        $this->response = $response ?: $this->response;

        return $this;
    }
353346
protected function createApiException(Request $request, Response $response)
    {
        //$errors = json_decode((string) $response->getBody());

        return new HttpRequestException(
            $response->getCode(),
            $response->getBody(),
            $request,
            $response
        );
    }
739253
public function modifyResponse(Request $request, Response $response)
    {
        if ($this->isCollect() === false) {
            return;
        }

        // if ($this -> created) {
        //     return;
        // }

        $app = $this->app;


        if ($app->runningInConsole() || !$this->isEnabled() || $this->isMyselfRequest()) {
            return $response;
        }

        // Show the Http Response Exception, when available
        if (isset($response->exception)) {
            $this->addThrowable($response->exception);
        }

        /**---------------------------------------------------------
         *   Display config settings
         *---------------------------------------------------------*/

        if ($this->shouldCollect('config', false)) {
            try {
                $configCollector = new ConfigCollector();
                $configCollector->setData($app['config']->all());
                $this->addCollector($configCollector);
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add ConfigCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        if ($this->app->bound(SessionManager::class)) {

            /** @var \Illuminate\Session\SessionManager $sessionManager */
            $sessionManager = $app->make(SessionManager::class);
            $httpDriver     = new SymfonyHttpDriver($sessionManager, $response);
            $this->setHttpDriver($httpDriver);

            if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
                try {
                    $this->addCollector(new SessionCollector($sessionManager));
                } catch (\Exception $e) {
                    $this->addThrowable(
                        new Exception(
                            'Cannot add SessionCollector to SongshenzongLog: ' . $e->getMessage(),
                            $e->getCode(),
                            $e
                        )
                    );
                }
            }
        } else {
            $sessionManager = null;
        }


        /**---------------------------------------------------------
         *   Only one can be enabled.
         *---------------------------------------------------------*/
        if ($this->shouldCollect('request', true) && !$this->hasCollector('request')) {
            try {
                $this->addCollector(new RequestCollector($request, $response, $sessionManager));
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add RequestCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        /**---------------------------------------------------------
         *   Just collect + store data
         *---------------------------------------------------------*/
        try {
            $this->collect();
        } catch (\Exception $e) {
            $app['log']->error('Songshenzong exception: ' . $e->getMessage());
        }


        return $response;
    }
907068
public function addFromResponse(ResponseInterface $response, RequestInterface $request)
    {
        $uri = $request->getUri();
        $host = $uri->getHost();
        $path = $uri->getPath() ?: '/';

        $cookies = static::parseSetCookieHeader($response->getHeader('Set-Cookie'));
        $cookies = $this->setRequestDefaults($cookies, $host, $path);
        $new = clone $this;
        foreach ($cookies as $cookie) {
            $new->cookies[$cookie->getId()] = $cookie;
        }
        $new->removeExpiredCookies($host, $path);

        return $new;
    }
522051
public function httpMkcol(RequestInterface $request, ResponseInterface $response)
    {
        $requestBody = $request->getBodyAsString();
        $path = $request->getPath();

        if ($requestBody) {
            $contentType = $request->getHeader('Content-Type');
            if (null === $contentType || (0 !== strpos($contentType, 'application/xml') && 0 !== strpos($contentType, 'text/xml'))) {
                // We must throw 415 for unsupported mkcol bodies
                throw new Exception\UnsupportedMediaType('The request body for the MKCOL request must have an xml Content-Type');
            }

            try {
                $mkcol = $this->server->xml->expect('{DAV:}mkcol', $requestBody);
            } catch (\Sabre\Xml\ParseException $e) {
                throw new Exception\BadRequest($e->getMessage(), 0, $e);
            }

            $properties = $mkcol->getProperties();

            if (!isset($properties['{DAV:}resourcetype'])) {
                throw new Exception\BadRequest('The mkcol request must include a {DAV:}resourcetype property');
            }
            $resourceType = $properties['{DAV:}resourcetype']->getValue();
            unset($properties['{DAV:}resourcetype']);
        } else {
            $properties = [];
            $resourceType = ['{DAV:}collection'];
        }

        $mkcol = new MkCol($resourceType, $properties);

        $result = $this->server->createCollection($path, $mkcol);

        if (is_array($result)) {
            $response->setStatus(207);
            $response->setHeader('Content-Type', 'application/xml; charset=utf-8');

            $response->setBody(
                $this->server->generateMultiStatus([$result])
            );
        } else {
            $response->setHeader('Content-Length', '0');
            $response->setStatus(201);
        }

        // Sending back false will interrupt the event chain and tell the server
        // we've handled this method.
        return false;
    }
726538
public function decorateResponse(Request $request, Response $response)
    {
        if ($request->headers->has(self::ORIGIN_REQUEST_HEADER)) {
            $request->headers->set('referer', $request->headers->get(self::ORIGIN_REQUEST_HEADER));
        }

        $this->setTurbolinksLocationHeaderFromSession($request, $response);

        if ($response->isRedirect() && $response->headers->has(self::ORIGIN_RESPONSE_HEADER)) {
            $this->redirectTo($request, $response);
        }

        $this->modifyStatusCode($request, $response);
    }
851887
public function run(RequestInterface $request, ResponseInterface $response)
    {
        unset($request);

        try {
            $this->start();
        } catch (Exception $e) {
            $this->climate()->error($e->getMessage());
        }

        return $response;
    }
804907
protected function dispatchProcess(Request $request, Response $response)
    {
        if ($request->getController() === null || $request->getAction() === null) {
            throw new ArchException('Controller or action not defined. Router problem?');
        }
        $actionMethod = $request->getAction() . 'Action';
        ob_start();
        $this->dispatched = true;
        $controllerName = $request->getController();
        if (!$controllerName) {
            throw new ArchException('Controller is undefined');
        }
        $controller = Container::getController($controllerName);
        if (!($controller instanceof \Osf\Controller\Action)) {
            throw new ArchException('Your controller class for application ' . $request->getController() . ' must extends \Osf\Controller\Action');
        }
        if (!method_exists($controller, $actionMethod)) {
            throw new HttpException('Action ' . $actionMethod . '() not found in controller class of application ' . $request->getController(), 404);
        }
        if ($this->dispatched) {
            $controller->preDispatch();
            self::debug('Call ' . $controllerName . '::' . $actionMethod . '()');
            $viewParams = $controller->$actionMethod();
            $controller->postDispatch();
            $content = ob_get_clean();
            $content && $response->appendBody($content);
            if ($viewParams === null) {
                $viewParams = [];
            } elseif (!is_array($viewParams)) {
                throw new ArchException('Action must return an array or null');
            }
        } else {
            self::debug('No call of ' . $controllerName . '::' . $actionMethod . '(), not dispatched');
            ob_clean();
        }
        if ($this->dispatched && $this->renderView) {
            $response->appendBody(Container::getView()->register($viewParams)->render());
        }

        return $this;
    }
565230
protected function cacheResponse(RequestInterface $request, ResponseInterface $response)
    {
        $cacheItem = $this->createCacheItem($this->createKeyFromRequest($request));
        $value = $response->getBody()->__toString();
        $cacheItem->set($value);

        $this
            ->getCacheItemPool()
            ->save($cacheItem);
    }
348630
protected function forceStatusCodeHttpOK(
        Request $request,
        SymfonyResponse $response,
        ResponseModelInterface $responseModel
    ) {
        if ($request->headers->has('X-Force-Status-Code-200')
            || ($request->getRequestFormat(
                ) == Format::FORMAT_JSON && $request->query->has(
                    self::PARAMETER_CALLBACK
                ))
        ) {
            $responseModel->setReturnStatusCode(true);
            $response->setStatusCode(Response::HTTP_OK);
            $response->headers->set('X-Status-Code', Response::HTTP_OK);
        }
    }
1130948
public function call(Request $request, Response $response) : Response {

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

	}
1071247
public function next(Request $request, Response $response, $next)
    {
        $response->setContentType('text/json');
        $next($request, $response);
    }