Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StreamHandler.php

function StreamHandler::createResponse

Parameters

resource $stream:

1 call to StreamHandler::createResponse()
StreamHandler::__invoke in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
Sends an HTTP request.

File

vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php, line 104

Class

StreamHandler
HTTP handler that uses PHP's HTTP stream wrapper.

Namespace

GuzzleHttp\Handler

Code

private function createResponse(RequestInterface $request, array $options, $stream, ?float $startTime) : PromiseInterface {
    $hdrs = $this->lastHeaders;
    $this->lastHeaders = [];
    try {
        [
            $ver,
            $status,
            $reason,
            $headers,
        ] = HeaderProcessor::parseHeaders($hdrs);
    } catch (\Exception $e) {
        return P\Create::rejectionFor(new RequestException('An error was encountered while creating the response', $request, null, $e));
    }
    [
        $stream,
        $headers,
    ] = $this->checkDecode($options, $headers, $stream);
    $stream = Psr7\Utils::streamFor($stream);
    $sink = $stream;
    if (\strcasecmp('HEAD', $request->getMethod())) {
        $sink = $this->createSink($stream, $options);
    }
    try {
        $response = new Psr7\Response($status, $headers, $sink, $ver, $reason);
    } catch (\Exception $e) {
        return P\Create::rejectionFor(new RequestException('An error was encountered while creating the response', $request, null, $e));
    }
    if (isset($options['on_headers'])) {
        try {
            $options['on_headers']($response);
        } catch (\Exception $e) {
            return P\Create::rejectionFor(new RequestException('An error was encountered during the on_headers event', $request, $response, $e));
        }
    }
    // Do not drain when the request is a HEAD request because they have
    // no body.
    if ($sink !== $stream) {
        $this->drain($stream, $sink, $response->getHeaderLine('Content-Length'));
    }
    $this->invokeStats($options, $request, $startTime, $response, null);
    return new FulfilledPromise($response);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal