You are here

private function CurlFactory::applyBody in Auth0 Single Sign On 8.2

1 call to CurlFactory::applyBody()
CurlFactory::applyMethod in vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php

File

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

Class

CurlFactory
Creates curl resources from a request

Namespace

GuzzleHttp\Handler

Code

private function applyBody(RequestInterface $request, array $options, array &$conf) {
  $size = $request
    ->hasHeader('Content-Length') ? (int) $request
    ->getHeaderLine('Content-Length') : null;

  // Send the body as a string if the size is less than 1MB OR if the
  // [curl][body_as_string] request value is set.
  if ($size !== null && $size < 1000000 || !empty($options['_body_as_string'])) {
    $conf[CURLOPT_POSTFIELDS] = (string) $request
      ->getBody();

    // Don't duplicate the Content-Length header
    $this
      ->removeHeader('Content-Length', $conf);
    $this
      ->removeHeader('Transfer-Encoding', $conf);
  }
  else {
    $conf[CURLOPT_UPLOAD] = true;
    if ($size !== null) {
      $conf[CURLOPT_INFILESIZE] = $size;
      $this
        ->removeHeader('Content-Length', $conf);
    }
    $body = $request
      ->getBody();
    if ($body
      ->isSeekable()) {
      $body
        ->rewind();
    }
    $conf[CURLOPT_READFUNCTION] = function ($ch, $fd, $length) use ($body) {
      return $body
        ->read($length);
    };
  }

  // If the Expect header is not present, prevent curl from adding it
  if (!$request
    ->hasHeader('Expect')) {
    $conf[CURLOPT_HTTPHEADER][] = 'Expect:';
  }

  // cURL sometimes adds a content-type by default. Prevent this.
  if (!$request
    ->hasHeader('Content-Type')) {
    $conf[CURLOPT_HTTPHEADER][] = 'Content-Type:';
  }
}