Make WordPress Core

Changeset 22047


Ignore:
Timestamp:
09/27/2012 06:54:17 AM (12 years ago)
Author:
dd32
Message:

Allow wp_remote_post to send a body consisting of entirely '0', which may be used when PUT'ing or POST'ing data to a API which accepts a raw chunk of data rather than key=value pairs (Such as some REST API's). Fixes #14184

File:
1 edited

Legend:

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

    r21996 r22047  
    170170            $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
    171171
    172         if ( empty($r['body']) ) {
    173             $r['body'] = null;
    174             // Some servers fail when sending content without the content-length header being set.
    175             // Also, to fix another bug, we only send when doing POST and PUT and the content-length
    176             // header isn't already set.
    177             if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) )
    178                 $r['headers']['Content-Length'] = 0;
    179         } else {
     172        if ( strlen( $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) {
    180173            if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
    181174                $r['body'] = http_build_query( $r['body'], null, '&' );
     175
    182176                if ( ! isset( $r['headers']['Content-Type'] ) )
    183177                    $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
    184                 $r['headers']['Content-Length'] = strlen( $r['body'] );
    185178            }
     179
     180            if ( '' === $r['body'] )
     181                $r['body'] = null;
    186182
    187183            if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
     
    915911        }
    916912
    917         if ( ! empty($r['body'] ) )
     913        if ( ! is_null( $r['body'] ) )
    918914            $arrContext['http']['content'] = $r['body'];
    919915
     
    11081104            default:
    11091105                curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] );
    1110                 if ( ! empty( $r['body'] ) )
     1106                if ( ! is_null( $r['body'] ) )
    11111107                    curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
    11121108                break;
Note: See TracChangeset for help on using the changeset viewer.