OK, so for people using the #ActivityPub #WordPress plugin from @pfefferle and are using caching that causes problems with return #JSON to web visitor, instead of #HTML, or HTML to ActivityPub requests instead of JSON, I think I have a working solution. I have just finally got around to testing my theory on my #OpenLiteSpeed server by leveraging a Rewrite Rule. I haven't fully confirmed if the requests are being cached.

1/2

I'm using this rewrite rule for #WordPress to redirect with an explicit content type request when the Accept type is `application/activity+json`:

#BEGIN ActivityPub Cache Handling
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} "application/activity+json"
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}?format=application/activity+json [R=301,L]
</IfModule>
#END ActivityPub Cache Handling

2/2

So I'm rather confused about whether this rewrite rule is actually working. When I test with the Boomerang Chrome extension and set the Request Accept header to "application/activity+json" I get JSON, from multiple URLs and HTML when I use "text/html". However, when testing with the Postman web tool, all I get is HTML no matter what.

...well, I tried a traditional curl request and it is responding just like Postman. So the Boomerang plugin is sending a request that is bypassing the cache.

OK, so I'm not sure about a broader solution. However, I have finally figured out how to properly cache HTML & Activity+JSON requests with #OpenLiteSpeed & the #ActivityPub plugin for #WordPress. It is possible that this might be usable for an #Apache setup using my original redirect method.

1/2

So the solution for #OpenLiteSpeed caching is to use this in order to have 2 different caches for the same endpoint.

#BEGIN ActivityPub Cache Handling
<IfModule LiteSpeed>
RewriteEngine On
CacheLookup on
RewriteCond %{HTTP_ACCEPT} ^application\/activity\+json$
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+activitypub]
</IfModule>
#END ActivityPub Cache Handling

2/2

@pfefferle is there a place that we can start compiling guides for addressing caching issues with the #ActivityPub plugin. I think this will be a huge item for #WordPress people to get this working.

I wonder if we even start looking at building into the plugin a method for detecting the server platform and the caching that is being used and point them to solutions the guides appropriate for their setup?

Thanks to @futtta for finding that there are additional content types. This should match the #ActivityPub plugin for #WordPress.

https://github.com/pfefferle/wordpress-activitypub/blob/master/includes/class-activitypub.php#L78-L81

#BEGIN ActivityPub Cache Handling
<IfModule LiteSpeed>
RewriteEngine On
CacheLookup on
RewriteCond %{HTTP_ACCEPT} ^application\/((activity|ld)\+json|json|ld\+json.*profile.*activitystreams")$
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+activitypub]
</IfModule>
#END ActivityPub Cache Handling

wordpress-activitypub/class-activitypub.php at master · pfefferle/wordpress-activitypub

ActivityPub for WordPress. Contribute to pfefferle/wordpress-activitypub development by creating an account on GitHub.

GitHub