mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
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
git-svn-id: http://core.svn.wordpress.org/trunk@22047 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e14d191fb6
commit
97bfd2db9a
@ -169,21 +169,17 @@ class WP_Http {
|
|||||||
if ( WP_Http_Encoding::is_available() )
|
if ( WP_Http_Encoding::is_available() )
|
||||||
$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
|
$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
|
||||||
|
|
||||||
if ( empty($r['body']) ) {
|
if ( strlen( $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) {
|
||||||
$r['body'] = null;
|
|
||||||
// Some servers fail when sending content without the content-length header being set.
|
|
||||||
// Also, to fix another bug, we only send when doing POST and PUT and the content-length
|
|
||||||
// header isn't already set.
|
|
||||||
if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) )
|
|
||||||
$r['headers']['Content-Length'] = 0;
|
|
||||||
} else {
|
|
||||||
if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
|
if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
|
||||||
$r['body'] = http_build_query( $r['body'], null, '&' );
|
$r['body'] = http_build_query( $r['body'], null, '&' );
|
||||||
|
|
||||||
if ( ! isset( $r['headers']['Content-Type'] ) )
|
if ( ! isset( $r['headers']['Content-Type'] ) )
|
||||||
$r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
|
$r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
|
||||||
$r['headers']['Content-Length'] = strlen( $r['body'] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( '' === $r['body'] )
|
||||||
|
$r['body'] = null;
|
||||||
|
|
||||||
if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
|
if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
|
||||||
$r['headers']['Content-Length'] = strlen( $r['body'] );
|
$r['headers']['Content-Length'] = strlen( $r['body'] );
|
||||||
}
|
}
|
||||||
@ -914,7 +910,7 @@ class WP_Http_Streams {
|
|||||||
$arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
|
$arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty($r['body'] ) )
|
if ( ! is_null( $r['body'] ) )
|
||||||
$arrContext['http']['content'] = $r['body'];
|
$arrContext['http']['content'] = $r['body'];
|
||||||
|
|
||||||
$context = stream_context_create($arrContext);
|
$context = stream_context_create($arrContext);
|
||||||
@ -1107,7 +1103,7 @@ class WP_Http_Curl {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] );
|
curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] );
|
||||||
if ( ! empty( $r['body'] ) )
|
if ( ! is_null( $r['body'] ) )
|
||||||
curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
|
curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user