Route HEAD API requests through the GET callback method
fixes #34837 props danielbachhuber git-svn-id: https://develop.svn.wordpress.org/trunk@35758 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
14eae0a8a7
commit
2ddab3adf8
@ -780,7 +780,8 @@ class WP_REST_Server {
|
|||||||
$callback = $handler['callback'];
|
$callback = $handler['callback'];
|
||||||
$response = null;
|
$response = null;
|
||||||
|
|
||||||
if ( empty( $handler['methods'][ $method ] ) ) {
|
$checked_method = 'HEAD' === $method ? 'GET' : $method;
|
||||||
|
if ( empty( $handler['methods'][ $checked_method ] ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +121,16 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
$this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() );
|
$this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_head_request_handled_by_get() {
|
||||||
|
register_rest_route( 'head-request', '/test', array(
|
||||||
|
'methods' => array( 'GET' ),
|
||||||
|
'callback' => '__return_true',
|
||||||
|
) );
|
||||||
|
$request = new WP_REST_Request( 'HEAD', '/head-request/test' );
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass a capability which the user does not have, this should
|
* Pass a capability which the user does not have, this should
|
||||||
* result in a 403 error.
|
* result in a 403 error.
|
||||||
|
Loading…
Reference in New Issue
Block a user