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

Breadcrumb

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

function CurlFactory::applyBody

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

File

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

Class

CurlFactory
Creates curl resources from a request

Namespace

GuzzleHttp\Handler

Code

private function applyBody(RequestInterface $request, array $options, array &$conf) : void {
    $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] = static 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:';
    }
}

API Navigation

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