Send the response to the client by first sending all
headers and then echoing the response body.

@param RequestInterface $request
@param ResponseInterface $response
197246
private function send(RequestInterface $request, ResponseInterface $response)
    {
        // Send headers if no headers has been sent before this
        if (!headers_sent()) {
            // Send headers
            $this->sendHeaders($response);
        }

        // Check if we have any content to flush
        if (ob_get_level() > 1) {
            // Flush (send) the buffer that contains output that the application has generated
            while (ob_get_level() >= $this->outputBufferLevel) {
                ob_end_flush();
            }
        }

        // Set buffer level to null
        $this->outputBufferLevel = null;

        // Make sure it wasn't a HEAD request
        if ($request->getMethod() !== 'HEAD') {
            // Send the body to the client by echoing it
            echo $response->getBody();
        }
    }
65938
protected function sendEvent(RequestInterface $request, ResponseInterface $response)
    {
        $key = $this->getEventKey($request);
        $event = $this->events[$key];

        unset($this->events[$key]);

        $event->setExecutionStop();
        $event->setResponse($response);
        $this->eventDispatcher->dispatch(GuzzleHttpEvent::EVENT_NAME, $event);
    }
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);
    }
287343
public function sendRequest(RequestInterface $request): void
    {
        $requestId = $this->getRequestId($request);
        $this->pendingRequests[$requestId] = $this->createPromiseForRequest($request, true);
    }
683579
protected function sendResponse($respondent, $response)
    {
        $respondent->sendHeader($response->getStatusCode(), $response->headers);

        $respondent->sendBody($response->getContent());
    }
455427
public function run(RequestInterface $request, ResponseInterface $response)
    {
        // Unused parameter
        unset($request);

        // Lock script, to ensure it can not be run twice  at the same time (before previous instance is done).
        $this->startLock();

        $climate = $this->climate();

        $processedCallback = function($success, $failures, $skipped) use ($climate) {
            if (!empty($success)) {
                $climate->green()->out(sprintf('%s emails were successfully sent.', count($success)));
            }

            if (!empty($failures)) {
                $climate->red()->out(sprintf('%s emails were not successfully sent', count($failures)));
            }

            if (!empty($skipped)) {
                $climate->dim()->out(sprintf('%s emails were skipped.', count($skipped)));
            }
        };

        $queueManager = new EmailQueueManager([
            'logger' => $this->logger,
            'queue_item_factory' => $this->queueItemFactory
        ]);
        $queueManager->setProcessedCallback($processedCallback);
        $queueManager->processQueue();

        $this->stopLock();

        return $response;
    }
1030008
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $this->request = $request;
        $render = $this->request->getAttribute('render', true);
        if ($render) {
            $response = $this->render($response);
        }
        return $this->executeNext($request, $response);
    }
311393
public function handle(RequestInterface $request)
    {
        $response = $request->send();
        $headers = $response->getHeaders()->getAll();
        $body = $response->getBody(true);
        $statusCode = $response->getStatusCode();

        $symfonyHeaders = array();

        foreach ($headers as $keys) {
            /**
             * Transfer-Encoding type chunked is not suported by symfony response
             */
            if($keys->getName() == "Transfer-Encoding" && $keys->__toString() === 'chunked'){
                continue;
            }
            $symfonyHeaders[$keys->getName()] = $keys->__toString();
        }

        return new Response($body,$statusCode,$symfonyHeaders);
    }
886165
protected function send(
        ResponseInterface $response,
        string $body): ResponseInterface
    {
        if (!$body) {
            $response = $this->sendErrorDocument($response);
        }
        unset($this->errorDocument);
        $response = $response->withHeader(
            Response::HEADER_CONTENT_LENGTH,
            (string) strlen($body));
        header(Response::PROTOCOL
             . $response->getProtocolVersion() . " "
             . $response->getStatusCode() . " "
             . $response->getReasonPhrase());
        foreach ($response->getHeaders() as $key => $value) {
            header($key . ": " . implode("; ", $value));
        }
        $response->getBody()->write($body);
        return $response;
    }
424973
private function onRequestComplete(RequestInterface $request, ResponseInterface $response)
    {
        $hash = $this->hash($request);
        // Send the log message to the adapter, adding a category and host
        $priority = $response && $this->isError($response) ? LOG_ERR : LOG_DEBUG;
        $message = $this->formatter->format($request, $response);
        $event = $this->stopwatch->stop($hash);
        $this->logAdapter->log($message, $priority, array(
            'request'  => $request,
            'response' => $response,
            'time'     => $event->getDuration(),
        ));
    }
380317
public static function setResponse(ResponseInterface $response)
    {
        $coroutineId = self::getCoroutineId();
        self::$context[$coroutineId][self::RESPONSE_KEY] = $response;
    }
1224513
private function sendHeaders(ResponseInterface $response)
    {
        // Set proper protocol, status code (and reason phrase) header
        if ($response->getReasonPhrase()) {
            header(sprintf(
                'HTTP/%s %d %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ));
        } else {
            header(sprintf(
                'HTTP/%s %d',
                $response->getProtocolVersion(),
                $response->getStatusCode()
            ));
        }

        // Loop through all headers
        foreach ($response->getHeaders() as $name => $values) {
            // Sanitize header name
            $name  = $this->sanitizeHeaderName($name);
            // First iteration, if more than one header with the same name
            // exists the $first parameter to the header method will indicate
            // if a second (etc) header should replace the previous one or
            // if multiple headers with the same name should be sent
            $first = true;
            foreach ($values as $value) {
                // Send header
                header(sprintf('%s: %s', $name, $value), $first);
                $first = false;
            }
        }
    }
128866
private function handleRequest(RequestInterface $request, ResponseInterface $response): void
    {
        foreach ($this->routes as $route) {
            $routeMatch = $route->matches($request);

            if ($routeMatch === null) {
                continue;
            }

            $controllerClass = $routeMatch->getControllerClassName();
            $controller = new $controllerClass();

            /** @var ControllerInterface $controller */
            $controller->processRequest($this, $request, $response, $routeMatch->getAction(), $routeMatch->getParameters());

            return;
        }

        $response->setStatusCode(new StatusCode(StatusCode::NOT_FOUND));
    }
598973
public function processRequest(RequestInterface $request, ResponseInterface $response)
    {
        $this->result = new AjaxResult;

        try {
            $this->processRequestParent($request, $response);
        } catch (Exception $exception) {
            if (false === $this->protectedRequestMode) {
                throw $exception;
            }

            $this->result->clear();

            $errorMessage = ExtensionService::get()->isInDebugMode()
                ? $this->getDebugMessageForException($exception)
                : ContextService::get()->translate(self::DEFAULT_ERROR_MESSAGE_KEY);

            $error = new Error($errorMessage, 1490176818);
            $this->result->addError($error);
            $this->result->setData('errorCode', $exception->getCode());
        }

        // Cleaning every external message.
        ob_clean();

        $this->injectResultInResponse();
    }
35682
private function sendErrorDocument(
        ResponseInterface $response): ResponseInterface
        {
        if ($this->errorDocument && preg_match(
                "/^(4|5){1}[0-2]{1}[0-9]{1}$/", $response->getStatusCode())
            ) {
            $this->errorDocument = str_replace(
                "{status}", $response->getStatusCode(), $this->errorDocument
            );
            if ($this->errorDocument !== filter_input(INPUT_SERVER, "REQUEST_URI")) {
                $response = $response->withHeader(
                    Response::HEADER_REFRESH,
                    "0; " . $this->errorDocument
                );
            }
        }
        return $response;
    }
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
680749
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $promise = $this->sendAsyncRequest($request);

        return $promise->wait();
    }