WP Super Cache - add support for the Accept HTTP header#29456
WP Super Cache - add support for the Accept HTTP header#29456
Conversation
* Add it to the cache key if it's not text/html to avoid throwing away existing cache files. * Don't serve cached files unless visitor accepts text/html * Add wpsc_get_accept_header() to get Accept header and normalise it to application/json or text/html.
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Super Cache plugin:
|
thingalon
left a comment
There was a problem hiding this comment.
😊 I hope you don't mind, but I added a couple of comments and a separate variable to differentiate the accept header, from the accept header tag we add to the cache key. I feel it will make it easier to understand 6 months from now.
Seems to work, happy to 👍
* Update MariaDB image health check for v11 images. * Update container ID detection for docker-compose v2. * Pass `Accept: text/html` in requests for #29456. (Axios by default passes `application/json, text/plain, */*`).
* Update MariaDB image health check for v11 images. * Update container ID detection for docker-compose v2. * Pass `Accept: text/html` in requests for #29456. (Axios by default passes `application/json, text/plain, */*`).
* Update MariaDB image health check for v11 images. * Update container ID detection for docker-compose v2. * Pass `Accept: text/html` in requests for #29456. (Axios by default passes `application/json, text/plain, */*`).
This patch allows WP Super Cache to ignore requests from clients that don't accept text/html. That allows WordPress to serve whatever content they require, which may well be JSON data.
This was prompted by the ActivityPub plugin which uses /author/X/ to deliver metadata about the author on a WordPress website to the Fediverse. If you search for a URL through the search box in Mastodon, it expects a JSON payload.
JSON requests are not cached by this plugin (yet?) but the vast majority of requests are text/html ones.
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Apply patch.
Enable debugging in the plugin.
Go to your Mastodon account and search for a blog post on your blog.
Go to the debug output and filter it to search for your blog post.
Note that it says:
The content of your post should appear in the search box in your Mastodon client.