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

Breadcrumb

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

function StreamHandler::checkDecode

Parameters

resource $stream:

1 call to StreamHandler::checkDecode()
StreamHandler::createResponse in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php

File

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

Class

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

Namespace

GuzzleHttp\Handler

Code

private function checkDecode(array $options, array $headers, $stream) : array {
    // Automatically decode responses when instructed.
    if (!empty($options['decode_content'])) {
        $normalizedKeys = Utils::normalizeHeaderKeys($headers);
        if (isset($normalizedKeys['content-encoding'])) {
            $encoding = $headers[$normalizedKeys['content-encoding']];
            if ($encoding[0] === 'gzip' || $encoding[0] === 'deflate') {
                $stream = new Psr7\InflateStream(Psr7\Utils::streamFor($stream));
                $headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']];
                // Remove content-encoding header
                unset($headers[$normalizedKeys['content-encoding']]);
                // Fix content-length header
                if (isset($normalizedKeys['content-length'])) {
                    $headers['x-encoded-content-length'] = $headers[$normalizedKeys['content-length']];
                    $length = (int) $stream->getSize();
                    if ($length === 0) {
                        unset($headers[$normalizedKeys['content-length']]);
                    }
                    else {
                        $headers[$normalizedKeys['content-length']] = [
                            $length,
                        ];
                    }
                }
            }
        }
    }
    return [
        $stream,
        $headers,
    ];
}

API Navigation

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