Skip to content

Instantly share code, notes, and snippets.

@soderlind
Forked from carlalexander/expect-header-fix.php
Created March 10, 2021 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/9c7f6d3820552d496ed56656d7537f05 to your computer and use it in GitHub Desktop.
Save soderlind/9c7f6d3820552d496ed56656d7537f05 to your computer and use it in GitHub Desktop.
WordPress "Expect" header fix
<?php
/**
* By default, cURL sends the "Expect" header all the time which severely impacts
* performance. Instead, we'll send it if the body is larger than 1 mb like
* Guzzle does.
*/
function add_expect_header(array $arguments)
{
$arguments['headers']['expect'] = !empty($arguments['body']) && strlen($arguments['body']) > 1048576 ? '100-Continue' : '';
return $arguments;
}
add_filter('http_request_args', 'add_expect_header');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment