WordPress.org

Make WordPress Core

Changeset 11937


Ignore:
Timestamp:
09/15/2009 03:57:49 PM (11 years ago)
Author:
ryan
Message:

Fix content length setup. Props jacobsantos. fixes #10783

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/http.php

    r11932 r11937  
    209209     * @access public
    210210     * @since 2.7.0
     211     * @todo Refactor this code. The code in this method extends the scope of its original purpose
     212     *      and should be refactored to allow for cleaner abstraction and reduce duplication of the
     213     *      code. One suggestion is to create a class specifically for the arguments, however
     214     *      preliminary refactoring to this affect has affect more than just the scope of the
     215     *      arguments. Something to ponder at least.
    211216     *
    212217     * @param string $url URI resource.
     
    278283            $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
    279284
    280         if ( is_null($r['body']) ) {
    281             // Some servers fail when sending content without the content-length
    282             // header being set.
    283             $r['headers']['Content-Length'] = null;
     285        if ( empty($r['body']) ) {
     286            // Some servers fail when sending content without the content-length header being set.
     287            // Also, to fix another bug, we only send when doing POST and PUT and the content-length
     288            // header isn't already set.
     289            if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) )
     290                $r['headers']['Content-Length'] = 0;
     291
     292            // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in
     293            // this case is simply that we aren't sending any bodies and to get the transports that
     294            // don't support sending bodies along with those which do.
    284295            $transports = WP_Http::_getTransport($r);
    285296        } else {
     
    296307                $r['headers']['Content-Length'] = strlen($r['body']);
    297308
     309            // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
     310            // this case is simply that we are sending HTTP body and to get the transports that do
     311            // support sending the body. Not all do, depending on the limitations of the PHP core
     312            // limitations.
    298313            $transports = WP_Http::_postTransport($r);
    299314        }
Note: See TracChangeset for help on using the changeset viewer.