Make WordPress Core

Opened 23 months ago

#56481 new enhancement

Short-circuit HEAD methods in Core controllers

Reported by: timothyblynjacobs's profile TimothyBlynJacobs Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords:
Focuses: performance Cc:


The REST API has built-in support for responding to a HEAD request. If no callback is specifically registered for the method, the server will fallback to the associated GET handler. However, this means that the server is throwing away work when no response body is needed.

GET routes can be adapted to check if the WP_REST_Request::get_method is HEAD and if so skip preparing the response body. For single item routes, this is pretty straightforward.

It is a little more nebulous for collection routes. We still need to provide any headers like pagination which are currently prepared after the response body is generated.

I think we'd want to extract the pagination logic to it's own method. Then, before making the database query,
adjust the query to only return ids. This will give us enough information to build the pagination headers and allow us to send the HEAD response.


Change History (0)

Note: See TracTickets for help on using tickets.