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

Breadcrumb

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

function CurlFactory::createHeaderFn

1 call to CurlFactory::createHeaderFn()
CurlFactory::create in vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
Creates a cURL handle resource.

File

vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php, line 680

Class

CurlFactory
Creates curl resources from a request

Namespace

GuzzleHttp\Handler

Code

private function createHeaderFn(EasyHandle $easy) : callable {
    if (isset($easy->options['on_headers'])) {
        $onHeaders = $easy->options['on_headers'];
        if (!\is_callable($onHeaders)) {
            throw new \InvalidArgumentException('on_headers must be callable');
        }
    }
    else {
        $onHeaders = null;
    }
    return static function ($ch, $h) use ($onHeaders, $easy, &$startingResponse) {
        $value = \trim($h);
        if ($value === '') {
            $startingResponse = true;
            try {
                $easy->createResponse();
            } catch (\Exception $e) {
                $easy->createResponseException = $e;
                return -1;
            }
            if ($onHeaders !== null) {
                try {
                    $onHeaders($easy->response);
                } catch (\Exception $e) {
                    // Associate the exception with the handle and trigger
                    // a curl header write error by returning 0.
                    $easy->onHeadersException = $e;
                    return -1;
                }
            }
        }
        elseif ($startingResponse) {
            $startingResponse = false;
            $easy->headers = [
                $value,
            ];
        }
        else {
            $easy->headers[] = $value;
        }
        return \strlen($h);
    };
}

API Navigation

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