Make WordPress Core

Opened 6 years ago

#44174 new defect (bug)

wp_get_http_headers does not return status code or follow redirects

Reported by: tlhackque's profile tlhackque Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.6
Component: HTTP API Keywords:
Focuses: Cc:


wp_get_http_headers performs an HTTP HEAD request and returns a simple success or failure code. This function is listed as part of the "HTTP API" on

If the target resource issues a redirect, it is not followed, nor is the specific redirect code returned. It is possible to check for the Location header & follow the redirect manually. But wp_get_http_headers should, at least optionally, process redirects. It should also return the HTTP status code and message. One way to do this would be the Apache model - provide a Status pseudo-header in the response (e.g. 'Status' => '200 OK')

If a WordPress resource returns a 404 code, the result is 'success' with an HTML page suitable for humans - HEAD, of course, simply says content-type: text/html. This is indistinguishable from 200 for the page.

The underlying wp_safe_remote_head API seems to return the status, but it's not returned from wp_get_http_headers. Note that wp_safe_remote_head is not listed on the function reference page, so I assume is not intended for public use.

(If context matters, I'm using it to implement a shortcode in a plugin.)

I'm leaving this as a "bug" since failure to provide status prevents a caller from detecting errors and correctly processing a response.

Change History (0)

Note: See TracTickets for help on using tickets.