Skip to content

Commit

Permalink
Manage "Expect" header with cURL transport
Browse files Browse the repository at this point in the history
Fixes #453
  • Loading branch information
carlalexander committed Mar 12, 2021
1 parent 675728b commit 27dbddf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ protected function setup_handle($url, $headers, $data, $options) {
$headers['Connection'] = 'close';
}

// Add "Expect" header.
//
// By default, cURL adds a "Expect: 100-Continue" to most requests. This header can
// add as much as a second to the time it takes for cURL to perform a request. To
// prevent this, we need to set an empty "Expect" header. To match the behaviour of
// Guzzle, we'll add the empty header to requests that are smaller than 1 MB and use
// HTTP/1.1.
//
// https://curl.se/mail/lib-2017-07/0013.html
if (!isset($headers['Expect']) && 1.1 === $options['protocol_version']) {
$headers['Expect'] = strlen(is_array($arguments['body']) ? implode('', $body) : $arguments['body']) >= 1048576 ? '100-Continue' : '';
}

$headers = Requests::flatten($headers);

if (!empty($data)) {
Expand Down

0 comments on commit 27dbddf

Please sign in to comment.