Starts to process the request

@param ResponseInterface $response The response object to evaluate
@param bool              $emulate  If you really want it to echo (for testing)

@return array with request and response inside
517473
public function dispatch(ResponseInterface $response, bool $emulate = false)
    {
        $redirect = $response->getHeaders('Location');

        if ($redirect) {
            return $this->redirect($redirect, false, $emulate);
        }

        if (!$response->hasContent() && !$response->hasJson()) {
            $response->setStatus(404, '404 Not Found');

            //throw an exception
            throw HttpException::forResponseNotFound();
        }

        if (!$response->hasContent() && $response->hasJson()) {
            $response->addHeader('Content-Type', 'text/json');
            $response->setContent($response->get('json'));
        }

        if (!$response->getHeaders('Content-Type')) {
            $response->addHeader('Content-Type', 'text/html; charset=utf-8');
        }

        return $this->output($response, $emulate);
    }
338544
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $path = array_key_exists(self::QUERY_PARAM, $request->getQueryParams())
            ? $request->getQueryParams()[self::QUERY_PARAM]
            : '';
        $uri = Uri::create($request->getUri());
        $queryString = ltrim(
            str_replace(
                self::QUERY_PARAM."={$path}",
                '',
                $uri->getQuery()
            ),
            '&'
        );
        $uri = $uri->withPath(str_replace('//', '/', "/$path"))
            ->withQuery($queryString);
        /** @var ServerRequestInterface $request */
        $request = $request->withUri($uri);
        return $this->executeNext($request, $response);
    }
1337846
public function processResponse(ResponseInterface $response)
    {

        $body = $response->getBody();

        $object = json_decode($body);
        if (json_last_error() === JSON_ERROR_NONE) {
            // JSON is valid
            if (property_exists($object, '_embedded') && property_exists($object->_embedded, 'items')) {
                $return = $object->_embedded->items;
            } elseif (property_exists($object, 'error')) {
                if (is_array($object->message)) {
                    foreach ($object->message as $message) {
                        $output .= $message;
                    }
                    throw new \Exception($output);
                } else {
                    throw new \Exception($object->message);
                }
            } else {
                $return = $object;
            }
        } else {
            $return = $body;
        }

        return $return;
    }
1065360
public static function processResult(string $url, ResponseInterface $response)
    {
        $body = $response->getBody()->getContents();
        $body = Tools::jsonNumbersToString($body);
        $result = Json::decode($body);
        self::checkErrors($result, $url);

        return $result;
    }
730550
protected function getOutputResponse(
        ServerRequestInterface $request,
        ResponseInterface $response
    ) : ResponseInterface {
        ob_start();
        switch ($this->determineOutputType()) {
            case self::TYPE_JSON:
                $this->renderJSON($request, $response);
                break;
            case self::TYPE_XML:
                $this->renderXML($request, $response);
                break;
            case self::TYPE_PLAIN:
                $this->renderPlainText($request, $response);
                break;
            default:
                $this->renderHTML($request, $response);
                break;
        }

        $output = ob_get_clean();
        $body = new RequestBody();
        // write handler
        $body->write($output);
        return $response->withStatus(404)->withBody($body);
    }
491322
public function renderIntoSetCookieHeader(ResponseInterface $response) : ResponseInterface
    {
        $response = $response->withoutHeader(static::SET_COOKIE_HEADER);
        foreach ($this->setCookies as $setCookie) {
            $response = $response->withAddedHeader(static::SET_COOKIE_HEADER, (string) $setCookie);
        }

        return $response;
    }
336298
public function render(bool $emulate = false)
    {
        $response = $this->getResponse();

        if (!$this->prepare()) {
            return $this;
        }

        if ($response->getStatus() == 200 && !$this->process()) {
            return $this;
        }

        $continue = true;

        //check for content
        //check for redirect
        if (!$response->hasContent()
            && !$response->hasJson()
            && !$this->hasRedirect()
        ) {
            $request = $this->getRequest();
            $response->setStatus(404, HttpHandler::STATUS_404);

            $error = new HttpException(HttpHandler::STATUS_404, 404);

            $continue = $this->getErrorProcessor()->process($request, $response, $error);
        }

        if ($continue) {
            $this->getDispatcher()->dispatch($response, $emulate);
        }

        //the connection is already closed
        //also remember there are no more sessions
        $this->shutdown();

        return $this;
    }
140023
protected function processResponse(Response $response, $expectedCode = 200)
	{
		if (202 == $response->code)
		{
			throw new \DomainException(
				'GitHub is building the statistics data. Please try again in a few moments.',
				$response->code
			);
		}

		return parent::processResponse($response, $expectedCode);
	}
760389
protected function parseResponse(ResponseInterface $response)
    {
        $content = (string) $response->getBody();

        if(strpos($content, "callback") !== false){
            $lpos = strpos($content, "(");
            $rpos = strrpos($content, ")");
            $content  = substr($content, $lpos + 1, $rpos - $lpos -1);

            return $this->parseJson($content);
        } else if(strpos($content, "access_token=") !== false) {
            $result = array();
            parse_str($content, $result);
            return $result;
        } else {
            return parent::parseResponse($response);
        }
    }
131435
protected function handleResponse(ResponseInterface $response): ResponseInterface
    {
        $contentType = $response->getHeader('Content-Type');

        if (in_array(self::CONTENT_TYPE_JSON_API, $contentType, true)) {
            $stream = $response->getBody();

            return new JsonApiResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $this->streamToDocument($stream)
            );
        }

        return $response;
    }
1157045
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
1306307
public function processResponse(ResponseInterface $response, SystemEvent $event)
    {
        if ($event->getName() === SystemEvent::FINISH) {
            $event->stopPropagation(true);
            $server  = $this->getServer();
            $emitter = $server->getEmitter();
            $emitter->emit($response);

            return;
        }
        $events = $this->getEvents();
        $event->setResult(SystemEvent::FINISH, $response);
        $events->trigger($event(SystemEvent::FINISH));
    }
940165
private function parseMakeUpExam(ResponseInterface $response)
    {
        $body = $this->checkAndThrow($response);

        // form => 考试形式, district => 校区
        return Parser::table($body, '#DataGrid1', [
            'code', 'name', 'student_name', 'time', 'location', 'seat', 'form'
        ], 7);
    }
643568
public function getResponse(\Phalcon\Http\Client\Response $response)
    {
        // get server response status
        $part = explode('|', $response->body);

        if ($part[0] > 1) {
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $part[1]);
        }

        return ($this->debug === true) ? [$response->header, $response] : $response->body;
    }
838465
protected function listResponseHeaders(ResponseInterface $response):\Generator
    {
        foreach ($response->getHeaders() as $header => $values) {
            foreach ($values as $value) {
                yield $header => $value;
            }
        }
    }
507482
public function run(RequestInterface $request, ResponseInterface $response)
    {
        $previousId    = $request->getParam('widget_id');
        $widgetType    = $request->getParam('widget_type');
        $widgetOptions = $request->getParam('widget_options');
        $withData      = $request->getParam('with_data');

        if ($previousId) {
            $failMessage = $this->translator()->translation('Failed to reload widget');
        } else {
            $failMessage = $this->translator()->translation('Failed to load widget');
        }
        $errorThrown = strtr($this->translator()->translation('{{ errorMessage }}: {{ errorThrown }}'), [
            '{{ errorMessage }}' => $failMessage
        ]);
        $reqMessage  = $this->translator()->translation(
            '{{ parameter }} required, must be a {{ expectedType }}, received {{ actualType }}'
        );
        $typeMessage = $this->translator()->translation(
            '{{ parameter }} must be a {{ expectedType }}, received {{ actualType }}'
        );

        try {
            if (!$widgetType) {
                $actualType = is_object($widgetType) ? get_class($widgetType) : gettype($widgetType);
                $this->addFeedback('error', strtr($reqMessage, [
                    '{{ parameter }}'    => '"obj_type"',
                    '{{ expectedType }}' => 'string',
                    '{{ actualType }}'   => $actualType,
                ]));
                $this->setSuccess(false);

                return $response->withStatus(400);
            }

            $widget = $this->widgetFactory()->create($widgetType);
            $widget->setView($this->widgetView());

            if (isset($widgetOptions)) {
                if (!is_array($widgetOptions)) {
                    $actualType = is_object($widgetOptions) ? get_class($widgetOptions) : gettype($widgetOptions);
                    $this->addFeedback('error', strtr($typeMessage, [
                        '{{ parameter }}'    => '"widget_options"',
                        '{{ expectedType }}' => 'array',
                        '{{ actualType }}'   => $actualType,
                    ]));
                    $this->setSuccess(false);

                    return $response->withStatus(400);
                }

                if (!isset($widgetOptions['type'])) {
                    $widgetOptions['type'] = $widgetType;
                }

                $widget->setData($widgetOptions);
            }


            $widgetHtml = $widget->renderTemplate($widget->template());
            $jsRequirements = $widget->renderTemplate('{{&jsRequirements}}');
            $js = $widget->renderTemplate('{{&js}}');
            $widgetId   = $widget->widgetId();

            $this->setWidgetHtml($jsRequirements.$widgetHtml.$js);
            $this->setWidgetId($widgetId);

            if ($withData) {
                $widgetData = $widget->widgetDataForJs();
                $this->setWidgetData($widgetData);
            }

            if ($previousId) {
                $doneMessage = $this->translator()->translation('Widget Reloaded');
            } else {
                $doneMessage = $this->translator()->translation('Widget Loaded');
            }
            $this->addFeedback('success', $doneMessage);
            $this->setSuccess(true);

            return $response;
        } catch (Exception $e) {
            $this->addFeedback('error', strtr($errorThrown, [
                '{{ errorThrown }}' => $e->getMessage()
            ]));
            $this->setSuccess(false);

            return $response->withStatus(500);
        }
    }
923444
protected function validateJson(ResponseInterface $response): array
    {
        try {
            return \GuzzleHttp\json_decode((string) $response->getBody(), true);
        } catch (\Exception $e) {
            return [];
        }
    }