Ticket #24987: 24987.diff
File 24987.diff, 3.1 KB (added by , 12 years ago) |
---|
-
tests/tests/http/base.php
259 259 260 260 } 261 261 262 /** 263 * Test HTTP Cookie handling 264 * 265 * @ticket 21182 266 */ 267 function test_cookie_handling() { 268 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1'; 269 270 $res = wp_remote_get( $url ); 271 $this->assertEquals( 'PASS', wp_remote_retrieve_body( $res ) ); 272 } 262 273 } -
tests/data/WPHTTP-testcase-redirection-script.php
96 96 exit; 97 97 } 98 98 99 if ( isset( $_GET['cookie-test'] ) ) { 100 if ( 'test-cookie' != $_GET['cookie-test'] ) { 101 setcookie( 'api_test_cookie', 'value', time() + 365*24*60*60, '/core/tests/1.0/', 'api.wordpress.org' ); 102 setcookie( 'api_test_cookie_minimal', 'value' ); 103 setcookie( 'api_test_cookie_wrong_host', 'value', time() + 365*24*60*60, '/', 'example.com' ); 104 setcookie( 'api_test_wildcard_domain', 'value', time() + 365*24*60*60, '/', '.wordpress.org' ); 105 setcookie( 'api_test_cookie_expired', 'value', time() - 365*24*60*60, '/', '.wordpress.org' ); 106 header( "Location: $url?cookie-test=test-cookie" ); 107 exit; 108 } 109 110 if ( empty( $_COOKIE['api_test_cookie'] ) || 'value' != $_COOKIE['api_test_cookie'] ) 111 die( 'FAIL_NO_COOKIE' ); 112 if ( empty( $_COOKIE['api_test_cookie_minimal'] ) ) 113 die( 'FAIL_NO_MINIMAL' ); 114 if ( isset( $_COOKIE['api_test_cookie_wrong_host'] ) ) 115 die( 'FAIL_WRONG_HOST' ); 116 if ( empty( $_COOKIE['api_test_wildcard_domain'] ) ) 117 die( 'FAIL_NO_WILDCARD' ); 118 if ( isset( $_COOKIE['api_test_cookie_expired'] ) ) 119 die( 'FAIL_EXPIRED_COOKIE' ); 120 121 echo 'PASS'; 122 exit; 123 } 124 125 99 126 $rt = isset($_GET['rt']) ? $_GET['rt'] : 5; 100 127 $r = isset($_GET['r']) ? $_GET['r'] : 0; 101 128 -
src/wp-includes/class-http.php
195 195 $r['headers']['Content-Length'] = strlen( $r['body'] ); 196 196 } 197 197 198 return $this->_dispatch_request($url, $r); 198 $response = $this->_dispatch_request($url, $r); 199 200 // Append cookies that were used in this request to the response 201 if ( ! empty( $r['cookies'] ) ) { 202 $cookies_set = wp_list_pluck( $response['cookies'], 'name' ); 203 foreach ( $r['cookies'] as $cookie ) { 204 if ( ! in_array( $cookie->name, $cookies_set ) && $cookie->test( $url ) ) { 205 $response['cookies'][] = $cookie; 206 } 207 } 208 } 209 210 return $response; 199 211 } 200 212 201 213 /** … … 638 650 $args['method'] = 'GET'; 639 651 } 640 652 653 // Include valid cookies in the redirect process 654 if ( ! empty( $response['cookies'] ) ) { 655 foreach ( $response['cookies'] as $cookie ) { 656 if ( $cookie->test( $redirect_location ) ) 657 $args['cookies'][] = $cookie; 658 } 659 } 660 641 661 return wp_remote_request( $redirect_location, $args ); 642 662 } 643 663 }