You are here

private function CurlFactory::createHeaderFn in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php \GuzzleHttp\Handler\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 493

Class

CurlFactory
Creates curl resources from a request

Namespace

GuzzleHttp\Handler

Code

private function createHeaderFn(EasyHandle $easy) {
  if (!isset($easy->options['on_headers'])) {
    $onHeaders = null;
  }
  elseif (!is_callable($easy->options['on_headers'])) {
    throw new \InvalidArgumentException('on_headers must be callable');
  }
  else {
    $onHeaders = $easy->options['on_headers'];
  }
  return function ($ch, $h) use ($onHeaders, $easy, &$startingResponse) {
    $value = trim($h);
    if ($value === '') {
      $startingResponse = true;
      $easy
        ->createResponse();
      if ($onHeaders) {
        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);
  };
}