[wp-trac] [WordPress Trac] #57752: Improve rest_(allowed|exposed)_cors_headers filters
WordPress Trac
noreply at wordpress.org
Fri Feb 17 09:43:24 UTC 2023
#57752: Improve rest_(allowed|exposed)_cors_headers filters
-------------------------+-----------------------------
Reporter: bor0 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
In a use case where there are multiple REST endpoints, but we only want to
expose specific headers for specific endpoints, the filters
`rest_allowed_cors_headers` and `rest_exposed_cors_headers` do not have
any request in context and are quite limited in that regard.
It would've been ideal if we could write our code as such:
{{{
add_filter( 'rest_exposed_cors_headers', function( $headers, $request ) {
if ( '/foo/bar' === $request->get_route() ) {
$headers[] = 'X-RateLimit-Limit';
}
return $headers;
}, 10, 2 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57752>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list