WordPress.org

Make WordPress Core

Ticket #10783: http.10783.diff

File http.10783.diff, 2.3 KB (added by jacobsantos, 11 years ago)

Actual fix for POST and PUT

  • http.php

     
    208208         *
    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.
    213218         * @param str|array $args Optional. Override the defaults.
     
    277282                if ( WP_Http_Encoding::is_available() )
    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 {
    286297                        if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
     
    295306                        if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
    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                }
    300315