Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP Super Cache - add support for the Accept HTTP header #29456

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

donnchawp
Copy link
Contributor

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:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

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:

ACCEPT: application/json
wp_cache_serve_cache_file: visitor does not accept text/html. Not serving cached file.
Page not cached by WP Super Cache. No closing HTML tag. Check your theme.
wp_cache_shutdown_callback: No cache file created. Returning.

The content of your post should appear in the search box in your Mastodon client.

* 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.
@donnchawp donnchawp added [Status] Needs Team Review [Plugin] Super Cache A fast caching plugin for WordPress. labels Mar 14, 2023
@donnchawp donnchawp self-assigned this Mar 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Super Cache plugin:

  • Next scheduled release: April 4, 2023.
  • Scheduled code freeze: March 27, 2023.

Copy link
Member

@thingalon thingalon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊 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 👍

@donnchawp donnchawp merged commit b683c49 into trunk Mar 15, 2023
@donnchawp donnchawp deleted the add/accept_header_supercache branch March 15, 2023 08:56
@github-actions github-actions bot added this to the super-cache/1.9.5 milestone Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Super Cache A fast caching plugin for WordPress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants