[wp-trac] [WordPress Trac] #56481: Short-circuit HEAD methods in Core controllers

WordPress Trac noreply at wordpress.org
Wed Aug 31 19:53:43 UTC 2022


#56481: Short-circuit HEAD methods in Core controllers
-------------------------------+-----------------------------
 Reporter:  TimothyBlynJacobs  |      Owner:  (none)
     Type:  enhancement        |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  REST API           |    Version:  4.7
 Severity:  normal             |   Keywords:
  Focuses:  performance        |
-------------------------------+-----------------------------
 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.

 See https://github.com/WordPress/gutenberg/pull/43703

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56481>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list