Custom request headers are always null
-
Hey there,
I try to separate the caches using a custom header field. I used:
function legals_add_cacheable_request_headers( $cacheable_headers ) { if ( !is_array($cacheable_headers) ) $cacheable_headers = array(); $cacheable_headers['wp/v2/legals_text'] = 'X-Legals_Control'; $cacheable_headers['wp/v2/legals_text'] = 'X-Legals_Control,X-Legals_Control-2'; return $cacheable_headers; } add_filter('wp_rest_cache/cacheable_request_headers', '..._add_cacheable_request_headers', 10, 1);to register the headers for the specific routes in the plugin.
Then I changed the api calls to set the http header in the requests. But the cache entries only show
Request Headers: {"X-Legals_Control":null}A closer look into the plugin showed me, that this is not really supported, isnt it?
In class-endpoint-api.php:private function set_cacheable_request_headers() { $request = new \WP_REST_Request(); $server = new \WP_REST_Server(); $request->set_headers( $server->get_headers( wp_unslash( $_SERVER ) ) ); ...Only the header fields supported by the $_SERVER variable are considered. Is it the way it should work?
Also, I should mention that im using the version 2020.1.1. The newest isnt caching at all.
I would appreciate <our help.
Thanks
The topic ‘Custom request headers are always null’ is closed to new replies.