LiteSpeed overrides PHP Cache-Control headers for REST API endpoints
-
Hello,
I am developing a WordPress plugin that uses a custom REST API endpoint to deliver content in a cache-safe way. The endpoint is:
wp-json/qotd/v1/today
The plugin intentionally sets the following HTTP headers via PHP (WP_REST_Response):Cache-Control: public, max-age=X, must-revalidate
Expires: [midnight of current day]I have tested this under the following conditions – the behavior is identical in all cases:
- REST API caching explicitly disabled
- /wp-json/qotd/ added to “Do Not Cache URIs”
- Browser Cache enabled
- Browser Cache disabled
In every case, LiteSpeed replaces the Cache-Control header set by PHP with its own no-cache directive:
Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private— My Questions —
- Is this hardcoded behavior for all /wp-json/ endpoints?
- Is there any way to make LiteSpeed respect and pass through the original Cache-Control header set by PHP for a specific REST endpoint?
- Other plugins (e.g. SwiftAI) appear to have an option to respect existing Cache-Control headers – is there a similar mechanism available?
Thank you for your help.
Dieter
You must be logged in to reply to this topic.