-
Notifications
You must be signed in to change notification settings - Fork 12
Add support for content negotiation #28
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
Comments
Hi @ocean90, thanks for your comment! Unfortunately the
And in Safari I get:
This kind of variance will kill cache efficiency, so blindly varying on this header is not a great idea. What you can do for ActivityPub is normalize and filter the header, and set a specific variant flag with a custom cache config. For example:
I know some users do this to detect requests from smartphones based on the If you're looking for more information about custom cache configuration, my friend @roytanck published a post a while ago: https://roytanck.com/2022/01/13/tweaking-surge-by-adding-a-configuration-file/ Hope that helps! |
Thanks for the quick feedback. I was aware of the custom configuration file but wasn't sure if |
Got it working with the following config for // Content negotiation.
$representation = 'generic'; // Or just 'html'.
if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
$accept = strtolower( $_SERVER['HTTP_ACCEPT'] );
if ( str_contains( $accept, 'text/html' ) ) {
$representation = 'html';
} elseif (
// Based on https://github.com/pfefferle/wordpress-activitypub/blob/abef17b9ad5d8e346aca92008e3b2b13aaa4ebf4/includes/class-activitypub.php#L67-L84.
str_contains( $accept, 'application/json' ) ||
str_contains( $accept, 'application/activity+json' ) ||
str_contains( $accept, 'application/ld+json' )
) {
$representation = 'json';
}
}
$config['variants']['representation'] = $representation;
unset( $accept, $representation );
return $config; Thanks again! |
Nice, thanks for sharing @ocean90! Also IIRC you have to return Lines 53 to 56 in b0f2a2d
|
Right, I already had that in my config. Updated above in case anyone wants to copy it as is. |
Found the issue pluginkollektiv/cachify#265 and noticed that it also applies to Surge.
This can be reproduced with the ActivityPub plugin active which serves different content based on the accept header. Example:
@kovshenin Should the accept header be added to the cache key or should the cache be skipped for non-HTML requests somewhere here? Or something else?
The text was updated successfully, but these errors were encountered: