Some coding standards cleanups for WP_HTTP. Props hakre for initial patch. See #13897

git-svn-id: http://svn.automattic.com/wordpress/trunk@15285 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-06-19 07:02:09 +00:00
parent b55852aad0
commit 9615351ae6
1 changed files with 25 additions and 25 deletions

View File

@ -238,39 +238,39 @@ class WP_Http {
if ( false !== $pre ) if ( false !== $pre )
return $pre; return $pre;
$arrURL = parse_url($url); $arrURL = parse_url( $url );
if ( empty( $url ) || empty( $arrURL['scheme'] ) ) if ( empty( $url ) || empty( $arrURL['scheme'] ) )
return new WP_Error('http_request_failed', __('A valid URL was not provided.')); return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
if ( $this->block_request( $url ) ) if ( $this->block_request( $url ) )
return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.')); return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) );
// Determine if this is a https call and pass that on to the transport functions // Determine if this is a https call and pass that on to the transport functions
// so that we can blacklist the transports that do not support ssl verification // so that we can blacklist the transports that do not support ssl verification
$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
// Determine if this request is to OUR install of WordPress // Determine if this request is to OUR install of WordPress
$homeURL = parse_url( get_bloginfo('url') ); $homeURL = parse_url( get_bloginfo( 'url' ) );
$r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host']; $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
unset($homeURL); unset( $homeURL );
if ( is_null( $r['headers'] ) ) if ( is_null( $r['headers'] ) )
$r['headers'] = array(); $r['headers'] = array();
if ( ! is_array($r['headers']) ) { if ( ! is_array( $r['headers'] ) ) {
$processedHeaders = WP_Http::processHeaders($r['headers']); $processedHeaders = WP_Http::processHeaders( $r['headers'] );
$r['headers'] = $processedHeaders['headers']; $r['headers'] = $processedHeaders['headers'];
} }
if ( isset($r['headers']['User-Agent']) ) { if ( isset( $r['headers']['User-Agent'] ) ) {
$r['user-agent'] = $r['headers']['User-Agent']; $r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']); unset( $r['headers']['User-Agent'] );
} }
if ( isset($r['headers']['user-agent']) ) { if ( isset( $r['headers']['user-agent'] ) ) {
$r['user-agent'] = $r['headers']['user-agent']; $r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']); unset( $r['headers']['user-agent'] );
} }
// Construct Cookie: header if any cookies are set // Construct Cookie: header if any cookies are set
@ -283,42 +283,42 @@ class WP_Http {
// Some servers fail when sending content without the content-length header being set. // 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 // Also, to fix another bug, we only send when doing POST and PUT and the content-length
// header isn't already set. // header isn't already set.
if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) ) if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) )
$r['headers']['Content-Length'] = 0; $r['headers']['Content-Length'] = 0;
// The method is ambiguous, because we aren't talking about HTTP methods, the "get" in // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in
// this case is simply that we aren't sending any bodies and to get the transports that // this case is simply that we aren't sending any bodies and to get the transports that
// don't support sending bodies along with those which do. // don't support sending bodies along with those which do.
$transports = WP_Http::_getTransport($r); $transports = WP_Http::_getTransport( $r );
} else { } else {
if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
if ( ! version_compare(phpversion(), '5.1.2', '>=') ) if ( ! version_compare(phpversion(), '5.1.2', '>=') )
$r['body'] = _http_build_query($r['body'], null, '&'); $r['body'] = _http_build_query( $r['body'], null, '&' );
else else
$r['body'] = http_build_query($r['body'], null, '&'); $r['body'] = http_build_query( $r['body'], null, '&' );
$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']); $r['headers']['Content-Length'] = strlen( $r['body'] );
} }
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'] );
// The method is ambiguous, because we aren't talking about HTTP methods, the "post" in // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
// this case is simply that we are sending HTTP body and to get the transports that do // this case is simply that we are sending HTTP body and to get the transports that do
// support sending the body. Not all do, depending on the limitations of the PHP core // support sending the body. Not all do, depending on the limitations of the PHP core
// limitations. // limitations.
$transports = WP_Http::_postTransport($r); $transports = WP_Http::_postTransport( $r );
} }
do_action( 'http_api_debug', $transports, 'transports_list' ); do_action( 'http_api_debug', $transports, 'transports_list' );
$response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
foreach ( (array) $transports as $transport ) { foreach ( (array) $transports as $transport ) {
$response = $transport->request($url, $r); $response = $transport->request( $url, $r );
do_action( 'http_api_debug', $response, 'response', get_class($transport) ); do_action( 'http_api_debug', $response, 'response', get_class( $transport ) );
if ( ! is_wp_error($response) ) if ( ! is_wp_error( $response ) )
return apply_filters( 'http_response', $response, $r, $url ); return apply_filters( 'http_response', $response, $r, $url );
} }
@ -621,7 +621,7 @@ class WP_Http_Fsockopen {
if ( isset($r['headers']['User-Agent']) ) { if ( isset($r['headers']['User-Agent']) ) {
$r['user-agent'] = $r['headers']['User-Agent']; $r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']); unset($r['headers']['User-Agent']);
} else if( isset($r['headers']['user-agent']) ) { } else if ( isset($r['headers']['user-agent']) ) {
$r['user-agent'] = $r['headers']['user-agent']; $r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']); unset($r['headers']['user-agent']);
} }
@ -973,7 +973,7 @@ class WP_Http_Streams {
if ( isset($r['headers']['User-Agent']) ) { if ( isset($r['headers']['User-Agent']) ) {
$r['user-agent'] = $r['headers']['User-Agent']; $r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']); unset($r['headers']['User-Agent']);
} else if( isset($r['headers']['user-agent']) ) { } else if ( isset($r['headers']['user-agent']) ) {
$r['user-agent'] = $r['headers']['user-agent']; $r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']); unset($r['headers']['user-agent']);
} }
@ -1146,7 +1146,7 @@ class WP_Http_ExtHTTP {
if ( isset($r['headers']['User-Agent']) ) { if ( isset($r['headers']['User-Agent']) ) {
$r['user-agent'] = $r['headers']['User-Agent']; $r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']); unset($r['headers']['User-Agent']);
} else if( isset($r['headers']['user-agent']) ) { } else if ( isset($r['headers']['user-agent']) ) {
$r['user-agent'] = $r['headers']['user-agent']; $r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']); unset($r['headers']['user-agent']);
} }
@ -1296,7 +1296,7 @@ class WP_Http_Curl {
if ( isset($r['headers']['User-Agent']) ) { if ( isset($r['headers']['User-Agent']) ) {
$r['user-agent'] = $r['headers']['User-Agent']; $r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']); unset($r['headers']['User-Agent']);
} else if( isset($r['headers']['user-agent']) ) { } else if ( isset($r['headers']['user-agent']) ) {
$r['user-agent'] = $r['headers']['user-agent']; $r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']); unset($r['headers']['user-agent']);
} }