Make WordPress Core


Ignore:
Timestamp:
03/02/2025 10:05:08 PM (3 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Improve performance for HEAD requests.

By default, the REST API responds to HEAD rqeuests by calling the GET handler and omitting the body from the response. While convenient, this ends up performing needless work that slows down the API response time.

This commit adjusts the Core controllers to specifically handle HEAD requests by not preparing the response body.

Fixes #56481.
Props antonvlasenko, janusdev, ironprogrammer, swissspidy, spacedmonkey, mukesh27, mamaduka, timothyblynjacobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php

    r56819 r59899  
    176176        $response = $this->parent_controller->prepare_item_for_response( $template, $request );
    177177
     178        // Don't prepare the response body for HEAD requests.
     179        if ( $request->is_method( 'HEAD' ) ) {
     180            return $response;
     181        }
     182
    178183        $fields = $this->get_fields_for_response( $request );
    179184        $data   = $response->get_data();
Note: See TracChangeset for help on using the changeset viewer.