Fix URL checking and add phpdoc. Props jacobsantos. fixes #8787 for trunk

git-svn-id: https://develop.svn.wordpress.org/trunk@10320 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2009-01-06 17:29:24 +00:00
parent 2defde173c
commit fc9382deca
1 changed files with 14 additions and 3 deletions

View File

@ -257,6 +257,8 @@ class WP_Http {
} }
if ( is_null($r['body']) ) { if ( is_null($r['body']) ) {
// Some servers fail when sending content without the content-length
// header being set.
$r['headers']['Content-Length'] = 0; $r['headers']['Content-Length'] = 0;
$transports = WP_Http::_getTransport($r); $transports = WP_Http::_getTransport($r);
} else { } else {
@ -660,7 +662,7 @@ class WP_Http_Fopen {
if ( false === $arrURL ) if ( false === $arrURL )
return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url)); return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
$url = str_replace($arrURL['scheme'], 'http', $url); $url = str_replace($arrURL['scheme'], 'http', $url);
if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) )
@ -999,13 +1001,16 @@ class WP_Http_Curl {
unset($r['headers']['user-agent']); unset($r['headers']['user-agent']);
} }
// If timeout is a float less than 1, round it up to 1. // cURL extension will sometimes fail when the timeout is less than 1 as
// it may round down to 0, which gives it unlimited timeout.
if ( $r['timeout'] > 0 && $r['timeout'] < 1 ) if ( $r['timeout'] > 0 && $r['timeout'] < 1 )
$r['timeout'] = 1; $r['timeout'] = 1;
$handle = curl_init(); $handle = curl_init();
curl_setopt( $handle, CURLOPT_URL, $url); curl_setopt( $handle, CURLOPT_URL, $url);
// The cURL extension requires that the option be set for the HEAD to
// work properly.
if ( 'HEAD' === $r['method'] ) { if ( 'HEAD' === $r['method'] ) {
curl_setopt( $handle, CURLOPT_NOBODY, true ); curl_setopt( $handle, CURLOPT_NOBODY, true );
} }
@ -1024,6 +1029,7 @@ class WP_Http_Curl {
curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] ); curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] ); curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
// The option doesn't work with safe mode or when open_basedir is set.
if ( !ini_get('safe_mode') && !ini_get('open_basedir') ) if ( !ini_get('safe_mode') && !ini_get('open_basedir') )
curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
@ -1035,8 +1041,13 @@ class WP_Http_Curl {
else else
curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
// Cookies are not handled by the HTTP API currently. Allow for plugin
// authors to handle it themselves... Although, it is somewhat pointless
// without some reference.
do_action_ref_array( 'http_api_curl', array(&$handle) ); do_action_ref_array( 'http_api_curl', array(&$handle) );
// We don't need to return the body, so don't. Just execution request
// and return.
if ( ! $r['blocking'] ) { if ( ! $r['blocking'] ) {
curl_exec( $handle ); curl_exec( $handle );
curl_close( $handle ); curl_close( $handle );