From ef3b20c9494325bff978c6b4fbea3f89ff0df8bc Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sat, 17 Aug 2013 01:20:09 +0000 Subject: [PATCH] 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 --- wp-includes/class-http.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index ba30e278bd..86bf845c0b 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -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 ); } }