Make WordPress Core

Ticket #34837: 34837.1.diff

File 34837.1.diff, 1.4 KB (added by danielbachhuber, 9 years ago)
  • src/wp-includes/rest-api/class-wp-rest-server.php

    diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
    index 62f7343..2c46fd8 100644
    a b class WP_REST_Server { 
    780780                                $callback  = $handler['callback'];
    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                                }
    786787
  • tests/phpunit/tests/rest-api/rest-server.php

    diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
    index 248ba56..c9431f0 100644
    a b class Tests_REST_Server extends WP_Test_REST_TestCase { 
    121121                $this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() );
    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
    126136         * result in a 403 error.