Update wp_get_http() to handle redirections on HEAD requests. Un-deprecate $red header to track total redirections. See #10624

git-svn-id: http://svn.automattic.com/wordpress/trunk@13151 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-02-14 11:23:32 +00:00
parent 775bebfade
commit 03e3247608
1 changed files with 11 additions and 6 deletions

View File

@ -1236,15 +1236,15 @@ function do_enclose( $content, $post_ID ) {
* *
* @param string $url URL to fetch. * @param string $url URL to fetch.
* @param string|bool $file_path Optional. File path to write request to. * @param string|bool $file_path Optional. File path to write request to.
* @param bool $deprecated Deprecated. Not used. * @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false.
* @return bool|string False on failure and string of headers if HEAD request. * @return bool|string False on failure and string of headers if HEAD request.
*/ */
function wp_get_http( $url, $file_path = false, $deprecated = false ) { function wp_get_http( $url, $file_path = false, $red = 1 ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '2.7' );
@set_time_limit( 60 ); @set_time_limit( 60 );
if ( $red > 5 )
return false;
$options = array(); $options = array();
$options['redirection'] = 5; $options['redirection'] = 5;
@ -1261,6 +1261,11 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) {
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
$headers['response'] = $response['response']['code']; $headers['response'] = $response['response']['code'];
// WP_HTTP no longer follows redirects for HEAD requests.
if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
return wp_get_http( $headers['location'], $file_path, ++$red );
}
if ( false == $file_path ) if ( false == $file_path )
return $headers; return $headers;