WP_HTTP: Cookies: When following redirects, include the request cookies in the redirected requests. Fixes #24987

Built from https://develop.svn.wordpress.org/trunk@25046


git-svn-id: http://core.svn.wordpress.org/trunk@25033 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-08-17 01:20:09 +00:00
parent 29739b2508
commit ef3b20c949
1 changed files with 21 additions and 1 deletions

View File

@ -195,7 +195,19 @@ class WP_Http {
$r['headers']['Content-Length'] = strlen( $r['body'] );
}
return $this->_dispatch_request($url, $r);
$response = $this->_dispatch_request($url, $r);
// Append cookies that were used in this request to the response
if ( ! empty( $r['cookies'] ) ) {
$cookies_set = wp_list_pluck( $response['cookies'], 'name' );
foreach ( $r['cookies'] as $cookie ) {
if ( ! in_array( $cookie->name, $cookies_set ) && $cookie->test( $url ) ) {
$response['cookies'][] = $cookie;
}
}
}
return $response;
}
/**
@ -639,6 +651,14 @@ class WP_Http {
$args['method'] = 'GET';
}
// Include valid cookies in the redirect process
if ( ! empty( $response['cookies'] ) ) {
foreach ( $response['cookies'] as $cookie ) {
if ( $cookie->test( $redirect_location ) )
$args['cookies'][] = $cookie;
}
}
return wp_remote_request( $redirect_location, $args );
}
}