Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#24987 closed enhancement (fixed)

HTTP requests should handle passing Cookies on redirects

Reported by: dd32's profile dd32 Owned by: dd32's profile dd32
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.7
Component: HTTP API Keywords: has-patch commit
Focuses: Cc:

Description

A follow on from #21182

When a request is made a remote location which redirects, any set cookies are not used in the following requests.
This causes plugin developers to have to handle redirections manually, passing the cookies between calls.

In addition, any cookies used within the request, should be returned in the 'cookies' array. This is a slight behaviour change, Previously it'd only include cookies that were set, not those that were passed to it. I don't see this causing any significant change to existing code.

Working code and unit tests are available on #21182 and will be committed shortly.

Attachments (2)

24987.diff (3.1 KB) - added by dd32 11 years ago.
Requires 21182.3.diff​ includes Changes and Unit Tests
http.patch (506 bytes) - added by dllh 11 years ago.

Download all attachments as: .zip

Change History (8)

@dd32
11 years ago

Requires 21182.3.diff​ includes Changes and Unit Tests

#1 @dd32
11 years ago

  • Keywords has-patch commit added
  • Owner set to dd32
  • Status changed from new to accepted

#2 @dd32
11 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 25046:

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

#3 @dllh
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

If the $response we get back before doing the cookie addition is a WP_Error, then we get a "cannot use object of type WP_Error as array" error in line 202: $cookies_set = wp_list_pluck( $response['cookies'], 'name' ); , which results in a fatal error.

The forthcoming patch avoids the fatal by returning before adding the cookies if we've gotten a WP_Error back. Props @nacin.

@dllh
11 years ago

#4 @dllh
11 years ago

  • Cc daryl@… added

#5 @SergeyBiryukov
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 25114:

Avoid a fatal error in WP_Http::request() if $response is a WP_Error instance. props dllh, nacin. fixes #24987.

#6 @SergeyBiryukov
10 years ago

  • Version changed from trunk to 3.7
Note: See TracTickets for help on using tickets.