From 8d0c62ad5064216e1c6ce00a992dece08d93e5b7 Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Fri, 13 May 2016 05:10:52 +0000 Subject: [PATCH] HTTP API: Add browser compatibility hook for 3xx redirects. WordPress erroneously follows browser-style behaviour with 3xx redirects, where a POST to 302 becomes a GET. Requests instead follows the specification and keeps the same method. Requests also exposes a hook to allow changing the behaviour. [37428] used the wrong method of adding this hook, now corrected. See #33055. git-svn-id: https://develop.svn.wordpress.org/trunk@37429 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-http.php | 4 ++++ src/wp-includes/default-filters.php | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 30c3dc9ca1..7511c100ed 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -304,8 +304,12 @@ class WP_Http { 'timeout' => $r['timeout'], 'useragent' => $r['user-agent'], 'blocking' => $r['blocking'], + 'hooks' => new Requests_Hooks(), ); + // Ensure redirects follow browser behaviour. + $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) ); + if ( $r['stream'] ) { $options['filename'] = $r['filename']; } diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index c866c3732d..f7bfeb52fb 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -206,8 +206,7 @@ add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); add_filter( 'title_save_pre', 'trim' ); -add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 ); -add_action( 'requests-requests.before_redirect', array( 'WP_Http', 'browser_redirect_compatibility' ), 10, 5 ); +add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 ); // REST API filters. add_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );