Skip to content

Instantly share code, notes, and snippets.

@carlalexander
Last active June 12, 2025 07:10
Show Gist options
  • Select an option

  • Save carlalexander/c779b473f62dcd1a4ca26fcaa637ec59 to your computer and use it in GitHub Desktop.

Select an option

Save carlalexander/c779b473f62dcd1a4ca26fcaa637ec59 to your computer and use it in GitHub Desktop.

Revisions

  1. carlalexander revised this gist Jul 3, 2021. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions expect-header-fix.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,24 @@
    */
    function add_expect_header(array $arguments)
    {
    $arguments['headers']['expect'] = !empty($arguments['body']) && strlen($arguments['body']) > 1048576 ? '100-Continue' : '';
    $arguments['headers']['expect'] = '';

    if (is_array($arguments['body'])) {
    $bytesize = 0;
    $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arguments['body']));

    foreach ($iterator as $datum) {
    $bytesize += strlen((string) $datum);

    if ($bytesize >= 1048576) {
    $arguments['headers']['expect'] = '100-Continue';
    break;
    }
    }
    } elseif (!empty($arguments['body']) && strlen((string) $arguments['body']) > 1048576) {
    $arguments['headers']['expect'] = '100-Continue';
    }

    return $arguments;
    }
    add_filter('http_request_args', 'add_expect_header');
    add_filter('http_request_args', 'add_expect_header');
  2. carlalexander revised this gist Mar 10, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion expect-header-fix.php
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,10 @@
    * performance. Instead, we'll send it if the body is larger than 1 mb like
    * Guzzle does.
    */
    function add_expect_header($arguments)
    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');
  3. carlalexander created this gist Mar 10, 2021.
    12 changes: 12 additions & 0 deletions expect-header-fix.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?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($arguments)
    {
    $arguments['headers']['expect'] = !empty($arguments['body']) && strlen($arguments['body']) > 1048576 ? '100-Continue' : '';
    }
    add_filter('http_request_args', 'add_expect_header');