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/class-wp-rest-request.php

    r58706 r59899  
    163163
    164164    /**
     165     * Determines if the request is the given method.
     166     *
     167     * @since 6.8.0
     168     *
     169     * @param string $method HTTP method.
     170     * @return bool Whether the request is of the given method.
     171     */
     172    public function is_method( $method ) {
     173        return $this->get_method() === strtoupper( $method );
     174    }
     175
     176    /**
    165177     * Canonicalizes the header name.
    166178     *
Note: See TracChangeset for help on using the changeset viewer.