Make WordPress Core

Changeset 35758


Ignore:
Timestamp:
12/03/2015 04:34:00 PM (9 years ago)
Author:
markjaquith
Message:

Route HEAD API requests through the GET callback method

fixes #34837
props danielbachhuber

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r35741 r35758  
    781781                $response = null;
    782782
    783                 if ( empty( $handler['methods'][ $method ] ) ) {
     783                $checked_method = 'HEAD' === $method ? 'GET' : $method;
     784                if ( empty( $handler['methods'][ $checked_method ] ) ) {
    784785                    continue;
    785786                }
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r35671 r35758  
    122122    }
    123123
     124    public function test_head_request_handled_by_get() {
     125        register_rest_route( 'head-request', '/test', array(
     126            'methods'  => array( 'GET' ),
     127            'callback' => '__return_true',
     128        ) );
     129        $request = new WP_REST_Request( 'HEAD', '/head-request/test' );
     130        $response = $this->server->dispatch( $request );
     131        $this->assertEquals( 200, $response->get_status() );
     132    }
     133
    124134    /**
    125135     * Pass a capability which the user does not have, this should
Note: See TracChangeset for help on using the changeset viewer.