[wp-trac] [WordPress Trac] #46992: Add a filter which allows the HTTP headers for REST API Endpoints to be changed
WordPress Trac
noreply at wordpress.org
Mon Jul 8 15:31:52 UTC 2019
#46992: Add a filter which allows the HTTP headers for REST API Endpoints to be
changed
-------------------------+------------------------------
Reporter: sudar | Owner: adamsilverstein
Type: enhancement | Status: assigned
Priority: normal | Milestone: 5.3
Component: REST API | Version: 5.2
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+------------------------------
Comment (by aaemnnosttv):
@TimothyBlynJacobs is correct - it is currently possible to
add/remove/change headers sent by a REST request using the
[https://developer.wordpress.org/reference/hooks/rest_post_dispatch/]
filter.
{{{
add_filter( 'rest_post_dispatch', function ( \WP_REST_Response $response )
{
$headers = $response->get_headers();
$headers['X-Added-Header'] = 'Foo';
$response->set_headers( $headers );
return $response;
} );
}}}
This filter provides the Response, Server, and Request object instances to
the callback which should provide all the context necessary to modify the
response as needed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46992#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list