Copies the values from the request handler back to the passed HTTP response instance.

@param \AppserverIo\Psr\HttpMessage\ResponseInterface $httpResponse A HTTP response object

@return void
321154
public function copyToHttpResponse(ResponseInterface $httpResponse)
    {

        // create a local copy of the response
        $servletResponse = $this->servletResponse;

        // copy response values to the HTTP response
        $httpResponse->setStatusCode($servletResponse->getStatusCode());
        $httpResponse->setStatusReasonPhrase($servletResponse->getStatusReasonPhrase());
        $httpResponse->setVersion($servletResponse->getVersion());
        $httpResponse->setState($servletResponse->getState());

        // copy the body content to the HTTP response
        $httpResponse->appendBodyStream($servletResponse->getBodyStream());

        // copy headers to the HTTP response
        foreach ($servletResponse->getHeaders() as $headerName => $headerValue) {
            $httpResponse->addHeader($headerName, $headerValue);
        }

        // copy cookies to the HTTP response
        $httpResponse->setCookies($servletResponse->getCookies());
    }
916586
public function includeInResponse(HTTPResponse $response)
    {
        $this->processCombinedFiles();
        $jsRequirements = array();
        $cssRequirements = array();

        foreach ($this->getJavascript() as $file => $attributes) {
            $path = $this->pathForFile($file);
            if ($path) {
                $jsRequirements[] = str_replace(',', '%2C', $path);
            }
        }

        if (count($jsRequirements)) {
            $response->addHeader('X-Include-JS', implode(',', $jsRequirements));
        }

        foreach ($this->getCSS() as $file => $params) {
            $path = $this->pathForFile($file);
            if ($path) {
                $path = str_replace(',', '%2C', $path);
                $cssRequirements[] = isset($params['media']) ? "$path:##:$params[media]" : $path;
            }
        }

        if (count($cssRequirements)) {
            $response->addHeader('X-Include-CSS', implode(',', $cssRequirements));
        }
    }
1302064
private function respondOnOptionsRequest(int $httpResponseCode): void
    {
        http_response_code($httpResponseCode);
        header('Content-Type: application/json');
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: *');
        exit;
    }
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);
    }
968477
public function serveResponse(ResponseInterface $response)
    {
        // add increment
        $this->servedResponseCount++;
        $allowServeEmpty = $this->getConfiguration('serveEmptyResponse') === true;
        $setContentLength = $this->getConfiguration('setContentLength') === true;
        // Send response
        if (!headers_sent()) {
            // Headers
            foreach ($response->getHeaders() as $name => $values) {
                if (!$setContentLength && strtolower($name) === 'content-length') {
                    continue;
                }

                foreach ($values as $value) {
                    header(sprintf('%s: %s', $name, $value), false);
                }
            }

            // Re Set Status Header
            header(sprintf(
                'HTTP/%s %s %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ), true, $response->getStatusCode());
        }

        // Serve Response
        if ($allowServeEmpty || ! $this->isEmptyResponseCode($response->getStatusCode())) {
            $body = $response->getBody();
            if ($body->isSeekable()) {
                $body->rewind();
            }

            $chunkSize      = $this->getNormalizeResponseChunkSize();
            $contentLength  = $setContentLength
                ? $response->getHeaderLine('Content-Length')
                : null;

            if (!$contentLength) {
                $contentLength = $body->getSize();
                // set content length
                if ($setContentLength && !headers_sent()) {
                    header(sprintf('Content-Length: %d', $contentLength));
                }
            }

            // if use buffer create buffer
            $this->addCreateBuffer();
            if ($contentLength) {
                $amountToRead = $contentLength;
                while ($amountToRead > 0 && !$body->eof()) {
                    $data = $body->read(min($chunkSize, $amountToRead));
                    echo $data;
                    $amountToRead -= strlen($data);
                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            } else {
                while (!$body->eof()) {
                    echo $body->read($chunkSize);
                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            }
        }
    }
902411
protected function getResponseWithStatusCode(Response $responseConfig, ResponseInterface $httpResponse)
    {
        if ($responseConfig->getStatusCode()) {
            $httpResponse = $httpResponse->withStatus($responseConfig->getStatusCode());
        }

        return $httpResponse;
    }
317563
protected function doRequest(RequestInterface $httpRequest)
    {
        $httpRawResponse = $httpRequest->execute();
        $httpStatusCode = $httpRequest->getInfo(CURLINFO_HTTP_CODE);
        $httpRequest->close();

        return $this->buildResponse($httpStatusCode, $httpRawResponse);
    }
121692
public function sendResponseBody(ResponseInterface $response):void
    {
        if (($body = $response->getBody()->detach()) === null) {
            $body = $response->getBody()->__toString();
        }
        $this->sendBody($body);
    }
669300
public function doRequest(HttpRequestInterface $request)
    {
        $responseClass = $this->responseClass;

        /** @var HttpResponseInterface $responseObject */
        $responseObject = new $responseClass();

        return $responseObject->build($request);
    }
60472
public function updateResponse(ApplicationInterface $application, RequestInterface $request, ResponseInterface $response): void
    {
        $response->setStatusCode($this->statusCode);
        $response->setContent($this->content);
    }
351119
private function processThrottleData(ResponseInterface $response)
    {
        if (empty($rateLimit = $response->getHeader('X-RateLimit-Limit'))) {
            return;
        }

        if (empty($remaining = $response->getHeader('X-RateLimit-Remaining'))) {
            return;
        }

        if (!empty($reset = $response->getHeader('X-RateLimit-Reset'))) {
            $this->rateLimit->setEndOfThrottle(intval($reset[0]));
        } else {
            $this->rateLimit->setEndOfThrottle(null);
        }

        $this->rateLimit->setMaxPerMinute(intval($rateLimit[0]))->setRemaining(intval($remaining[0]));
    }
1159471
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);
        $code = $response->getStatusCode();
        $allowedCodes = array_keys($this->renderer) + array_keys($this->defaultErrors);
        if (in_array($code, $allowedCodes)) {
            if (!$response->getBody()->getSize()) {
                $format = FormatNegotiator::getPreferredFormat($request);

                if (isset($this->renderer[$code])) {
                    $content = $this->renderer[$code]($format);
                } else {
                    $content = $this->defaultRenderer($code, $format);
                }

                if (is_array($content)) {
                    $content = json_encode($content);
                }

                $body = $this->streamFactory->createStream($content);

                $response = $response->withBody($body);
                $response = $response->withStatus($code);

                if ($format === 'json') {
                    $response = $response->withHeader('content-type', 'application/json');
                } else {
                    $response = $response->withHeader('content-type', 'text/html; charset=utf-8');
                }
            }
        }

        return $response;
    }
629320
public function setBaseResponse(ResponseInterface $response)
    {
        if ($response instanceof GlobalEnvironmentInterface && $response->isStale()) {
            throw new \RuntimeException("Unable to set base response: Response is stale");
        }
        
        $this->baseResponse = $response;
    }
5709
protected function serveHeaders(ResponseInterface $response)
    {
        header_remove('X-Powered-By');
        foreach ($response->getHeaders() as $header => $values) {
            header($header . ': ' . array_shift($values), true);
            foreach ($values as $value) {
                header($header . ': ' . $value, false);
            }
        }
    }
87274
protected function getResponseWithHeaders(HttpResponse $responseConfig, ResponseInterface $httpResponse)
    {
        if ($responseConfig->getHeaders()) {
            /** @var \Mcustiel\Phiremock\Domain\Http\Header $header */
            foreach ($responseConfig->getHeaders() as $header) {
                $httpResponse = $httpResponse->withHeader(
                    $header->getName()->asString(),
                    $header->getValue()->asString()
                );
            }
        }

        return $httpResponse;
    }
1019653
protected function errorCheckResponse(ResponseInterface $response)
    {
        $body = $response->getBody();

        if ($response->getStatusCode() >= 400) {
            throw new HttpException($response);
        }

        $responseObject = @json_decode($this->streamToString($body));
        if (!isset($responseObject)) {
            throw new Exception('JSON returned is not valid', $response);
        }

        if (isset($responseObject->error)) {
            throw new Exception($responseObject->error, $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;
    }