Make WordPress Core

Ticket #35975: 35975.2.diff

File 35975.2.diff, 1.7 KB (added by joehoyle, 10 years ago)
  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index d4c0aca..3a5fc1a 100644
    a b function rest_handle_options_request( $response, $handler, $request ) { 
    431431                }
    432432
    433433                $data = $handler->get_data_for_route( $route, $endpoints, 'help' );
    434                 $accept = array_merge( $accept, $data['methods'] );
     434                $response->set_matched_route( $route );
    435435                break;
    436436        }
    437         $response->header( 'Accept', implode( ', ', $accept ) );
    438437
    439438        $response->set_data( $data );
    440439        return $response;
  • 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 7d5cf68..3c2c930 100644
    a b class Tests_REST_Server extends WP_Test_REST_TestCase { 
    285285                $this->assertEquals( $sent_headers['Allow'], 'POST' );
    286286        }
    287287
     288        public function test_allow_header_sent_on_options_request() {
     289                register_rest_route( 'test-ns', '/test', array(
     290                        array(
     291                                'methods'  => array( 'GET' ),
     292                                'callback' => '__return_null',
     293                        ),
     294                        array(
     295                                'methods'  => array( 'POST' ),
     296                                'callback' => '__return_null',
     297                                'permission_callback' => '__return_null',
     298                        ),
     299                ) );
     300
     301                $request = new WP_REST_Request( 'OPTIONS', '/test-ns/test' );
     302                $response = $this->server->dispatch( $request );
     303
     304                $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this->server, $request );
     305
     306                $headers = $result->get_headers();
     307
     308                $this->assertEquals( 'GET', $headers['Allow'] );
     309        }
     310
    288311        public function permission_denied() {
    289312                return new WP_Error( 'forbidden', 'You are not allowed to do this', array( 'status' => 403 ) );
    290313        }