Send the response with the rate limit headers.

@param \Dingo\Api\Http\Response $response

@return \Dingo\Api\Http\Response
549955
protected function responseWithHeaders($response)
    {
        foreach ($this->getHeaders() as $key => $value) {
            $response->headers->set($key, $value);
        }

        return $response;
    }
767871
protected function filterResponse($response)
    {
        $contentType = $response->getHeader('Content-Type');

        if (!$contentType || false === strpos($contentType, 'charset=')) {
            if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $response->getContent(), $matches)) {
                $headers = $response->getHeaders();
                $headers['Content-Type'] = $contentType.';charset='.$matches[1];

                $response = new Response($response->getContent(), $response->getStatus(), $headers);
            }
        }

        return parent::filterResponse($response);
    }
783867
protected function serializeResponse($response)
    {
        /** @var ResponseInterface $response */
        $serialized = serialize([
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody()->getContents(),
        ]);

        //subsequent calls need to access the stream from the beginning
        $response->getBody()->rewind();

        return $serialized;
    }
966521
public function sendBody(Response $response)
    {
        $body = $response->getBody();
        $body->rewind();
        echo $body->getContents();
        return $response;
    }
192545
private function persistResponse(Response $response)
    {
        $headers = $response->headers->all();
        $headers['X-Status'] = [$response->getStatusCode()];

        return $headers;
    }
18469
function extractRatelimit(\Psr\Http\Message\ResponseInterface $response) {
        $date = (new \DateTime($response->getHeader('Date')[0]))->getTimestamp();
        
        $limit = ($response->hasHeader('X-RateLimit-Limit') ? ((int) $response->getHeader('X-RateLimit-Limit')[0]) : null);
        $remaining = ($response->hasHeader('X-RateLimit-Remaining') ? ((int) $response->getHeader('X-RateLimit-Remaining')[0]) : null);
        $resetTime = ($response->hasHeader('Retry-After')
            ? ((float) \bcadd(\microtime(true), (((int) $response->getHeader('Retry-After')[0]) / 1000)))
            : ($response->hasHeader('X-RateLimit-Reset') ? ((float) \bcadd(\microtime(true), (((int) $response->getHeader('X-RateLimit-Reset')[0]) - $date))) : null)
        );
        
        return \compact('limit', 'remaining', 'resetTime');
    }
386601
public function emit(Response $response, $maxBufferLength = 8192)
    {
        $this->assertNoPreviousOutput();

        $this->emitHeaders($response);
        $this->emitStatusLine($response);
        
        if ($response->hasCallback()) {
            call_user_func($response->getCallback());
        } elseif ($response->hasHeader('Accept-Ranges')) {
            $range = $this->parseContentRange($response->getHeaderLine('Content-Range'));
            if (is_array($range) && $range[0] === 'bytes') {
                $this->emitBodyRange($range, $response, $maxBufferLength);
            } else {
                $body = $response->getBody();
                if ($body->isSeekable()) {
                    $body->rewind();
                }
                if (!$body->isReadable()) {
                    echo $body;
                } else {
                    while (!$body->eof()) {
                        echo $body->read($maxBufferLength);
                    }
                }
            }
        } else {
            echo $response->getBody();
        }
    }
537041
public function sendContent(DispatcherResponseInterface $response)
    {
        //Make sure we do not have body content for 204, 205 and 305 status codes
        $codes = array(HttpResponse::NO_CONTENT, HttpResponse::NOT_MODIFIED, HttpResponse::RESET_CONTENT);
        if (!in_array($response->getStatusCode(), $codes)) {
            echo $response->getStream()->toString();
        }

        return $this;
    }
958461
public function setRawResponse($response)
    {
        $parts = explode("\r\n\r\n", $response);

        if (count($parts) == 2) {
            $matches = array();
            $this->responseBody = $parts[1];

            if (preg_match_all(
                '/(HTTP\/[1-9]\.[0-9]\s+(?<statusCode>\d+)\s+(?<statusMessage>.*)'.
                        "|(?<headerName>[^:]+)\\s*:\\s*(?<headerValue>.*))\r\n/m",
                    $parts[0], $matches)) {
                foreach ($matches['statusCode'] as $offset => $match) {
                    if (!empty($match)) {
                        $this->statusCode = (int) $match;
                        $this->statusMessage = $matches['statusMessage'][$offset];
                        break;
                    }
                }

                foreach ($matches['headerName'] as $offset => $name) {
                    if (!empty($name)) {
                        $key = strtolower($name);
                        $header = array('name' => $name,
                            'value' => $matches['headerValue'][$offset],
                        );

                        if (isset($this->responseHeader[$key])) {
                            if (isset($this->responseHeader[$key]['name'])) {
                                $this->responseHeader[$key] = array(
                                    $this->responseHeader[$key],
                                );
                            }

                            $this->responseHeader[$key][] = $header;
                        } else {
                            $this->responseHeader[$key] = $header;
                        }
                    }
                }
            }
        } else {
            $this->responseBody = $response;
        }
    }
463222
public static function attachHeaders($response)
	{
		$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
		$response->headers->set('Access-Control-Allow-Headers', config('api.cors_allowed_headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With'));
		$response->headers->set('Access-Control-Allow-Credentials', 'true');
		
		if ($exposed = config('api.cors_exposed_headers', 'Pagination-Page, Pagination-Num, Pagination-Total, Pagination-Last-Page')) {
			$response->headers->set('Access-Control-Expose-Headers', $exposed);
		}
	}
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }
478399
protected function finish(Response $response)
    {
        if ($this->requestedResultsLocale !== '') {
            $this->getLocalization()->popActiveContext();
        }
        if (!$response->headers->has('X-Frame-Options')) {
            $response->headers->set('X-Frame-Options', 'DENY');
        }
        if (!$response->headers->has('Access-Control-Allow-Origin')) {
            $config = $this->app->make('community_translation/config');
            $response->headers->set('Access-Control-Allow-Origin', (string) $config->get('options.api.accessControlAllowOrigin'));
        }

        return $response;
    }
422230
public static function send ( $response ) {
      $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ?
          $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
      $code = $response->code();
      $status = ResponseCode::find( $code );
      $body = $response->body();
      header( "$protocol $code $status", true, intval( $code ) );
      foreach ( $response->headers() as $a => $v )
        header( "$a: $v" );
      if ( is_string( $body ) && strlen( $body ) > 0 )
        echo $body;
    }
683651
protected function response(Response $response)
    {
        return $this->response->create(
            (string)$response->getContent(),
            $response->getStatusCode(),
            (array)$response->headers->all()
        );
    }
1023112
private function send(Response $response, Request $request = null): \Generator
    {
        \assert($this->client, "The driver has not been setup; call setup first");

        if ($this->lastWrite) {
            yield $this->lastWrite; // Prevent writing another response until the first is finished.
        }

        $shouldClose = false;

        $protocol = $request !== null ? $request->getProtocolVersion() : "1.0";

        $status = $response->getStatus();
        $reason = $response->getReason();

        $headers = $this->filter($response, $protocol, $request ? $request->getHeaderArray("connection") : []);

        $chunked = !isset($headers["content-length"])
            && $protocol === "1.1"
            && $status >= Status::OK;

        if (!empty($headers["connection"])) {
            foreach ($headers["connection"] as $connection) {
                if (\strcasecmp($connection, "close") === 0) {
                    $chunked = false;
                    $shouldClose = true;
                }
            }
        }

        if ($chunked) {
            $headers["transfer-encoding"] = ["chunked"];
        }

        $buffer = "HTTP/{$protocol} {$status} {$reason}\r\n";
        $buffer .= Rfc7230::formatHeaders($headers);
        $buffer .= "\r\n";

        if ($request !== null && $request->getMethod() === "HEAD") {
            ($this->write)($buffer, $shouldClose);
            return;
        }

        $chunk = ""; // Required for the finally, not directly overwritten, even if your IDE says otherwise.
        $body = $response->getBody();
        $streamThreshold = $this->options->getStreamThreshold();

        try {
            while (null !== $chunk = yield $body->read()) {
                if (!($length = \strlen($chunk))) {
                    continue;
                }

                if ($chunked) {
                    $chunk = \sprintf("%x\r\n%s\r\n", $length, $chunk);
                }

                if (\strlen($buffer) < $streamThreshold) {
                    $buffer .= $chunk;
                    continue;
                }

                // Initially the buffer won't be empty and contains the headers.
                // We save a separate write or the headers here.
                $promise = ($this->write)($buffer);

                $buffer = $chunk;
                $chunk = ""; // Don't use null here, because of the finally

                yield $promise;
            }

            if ($buffer !== "" || $chunked || $shouldClose) {
                yield ($this->write)($chunked ? "{$buffer}0\r\n\r\n" : $buffer, $shouldClose);
            }
        } catch (ClientException $exception) {
            return; // Client will be closed in finally.
        } finally {
            if ($chunk !== null) {
                $this->client->close();
            }
        }
    }
76675
protected function sendResetResponse(Request $request, $response)
    {
        if ($request->expectsJson()) {
            return response()->json([
                'status' => trans($response)
            ]);
        }
        return redirect($this->redirectPath())
            ->with('status', trans($response));
    }
215742
private function willMakeFinalResponseUncacheable(Response $response)
    {
        // RFC2616: A response received with a status code of 200, 203, 300, 301 or 410
        // MAY be stored by a cache […] unless a cache-control directive prohibits caching.
        if ($response->headers->hasCacheControlDirective('no-cache')
            || $response->headers->getCacheControlDirective('no-store')
        ) {
            return true;
        }

        // Last-Modified and Etag headers cannot be merged, they render the response uncacheable
        // by default (except if the response also has max-age etc.).
        if (\in_array($response->getStatusCode(), [200, 203, 300, 301, 410])
            && null === $response->getLastModified()
            && null === $response->getEtag()
        ) {
            return false;
        }

        // RFC2616: A response received with any other status code (e.g. status codes 302 and 307)
        // MUST NOT be returned in a reply to a subsequent request unless there are
        // cache-control directives or another header(s) that explicitly allow it.
        $cacheControl = ['max-age', 's-maxage', 'must-revalidate', 'proxy-revalidate', 'public', 'private'];
        foreach ($cacheControl as $key) {
            if ($response->headers->hasCacheControlDirective($key)) {
                return false;
            }
        }

        if ($response->headers->has('Expires')) {
            return false;
        }

        return true;
    }