• Resolved zzusyu

    (@zzusyu)


    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

    • This topic was modified 5 years, 11 months ago by zzusyu.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @zzusyu

    Thank you for using our plugin!

    I just did some testing and at first my test were working perfectly fine with my own made-up headers. I then switched to using your headers and they weren’t working. The reason for this is the fact that you have an underscore _ in your header name. Most servers do not support underscores in header names and will drop these headers silently. And well, if we don’t get the headers from the server, there isn’t much we can do with them…
    So if you would be able to change the header name to not include underscores it would work perfectly fine 🙂

    Thread Starter zzusyu

    (@zzusyu)

    Hi @rockfire,

    had that in mind. Thought I tested that.

    Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom request headers are always null’ is closed to new replies.