rest_send_allow_header
函数
rest_send_allow_header ( $response, $server, $request )
- 参数
-
-
(WP_REST_Response)
$response
Current response being served.- Required: 是
-
(WP_REST_Server)
$server
ResponseHandler instance (usually WP_REST_Server).- Required: 是
-
(WP_REST_Request)
$request
The request that was used to make current response.- Required: 是
-
(WP_REST_Response)
- 返回值
-
- (WP_REST_Response) Response to be served, with “Allow” header if route has allowed methods.
- 定义位置
-
-
wp-includes/rest-api.php
, line 804
-
wp-includes/rest-api.php
- 引入
- 4.4.0
- 弃用
- –
Sends the “Allow” header to state all methods that can be sent to the current route.
function rest_send_allow_header( $response, $server, $request ) { $matched_route = $response->get_matched_route(); if ( ! $matched_route ) { return $response; } $routes = $server->get_routes(); $allowed_methods = array(); // Get the allowed methods across the routes. foreach ( $routes[ $matched_route ] as $_handler ) { foreach ( $_handler['methods'] as $handler_method => $value ) { if ( ! empty( $_handler['permission_callback'] ) ) { $permission = call_user_func( $_handler['permission_callback'], $request ); $allowed_methods[ $handler_method ] = true === $permission; } else { $allowed_methods[ $handler_method ] = true; } } } // Strip out all the methods that are not allowed (false values). $allowed_methods = array_filter( $allowed_methods ); if ( $allowed_methods ) { $response->header( 'Allow', implode( ', ', array_map( 'strtoupper', array_keys( $allowed_methods ) ) ) ); } return $response; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。