mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
REST API: Ensure "Allow" header is returned for OPTIONS requests.
This changeset ensures `$request->set_url_params()` is called while fulfilling OPTIONS requests, where previously it was skipped because OPTIONS requests short-circuit the logic in `dispatch` which handles this setup for other request methods. Omitting the URL parameters prevented the Allow header from being set. Props killua99, noisysocks. Fixes #45753. git-svn-id: https://develop.svn.wordpress.org/trunk@44933 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -615,12 +615,27 @@ function rest_handle_options_request( $response, $handler, $request ) {
|
||||
$data = array();
|
||||
|
||||
foreach ( $handler->get_routes() as $route => $endpoints ) {
|
||||
$match = preg_match( '@^' . $route . '$@i', $request->get_route() );
|
||||
$match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
|
||||
|
||||
if ( ! $match ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$args = array();
|
||||
foreach ( $matches as $param => $value ) {
|
||||
if ( ! is_int( $param ) ) {
|
||||
$args[ $param ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $endpoints as $endpoint ) {
|
||||
// Remove the redundant preg_match argument.
|
||||
unset( $args[0] );
|
||||
|
||||
$request->set_url_params( $args );
|
||||
$request->set_attributes( $endpoint );
|
||||
}
|
||||
|
||||
$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
|
||||
$response->set_matched_route( $route );
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user