Skip to content

Commit 3b21061

Browse files
authored
re-add vary header (#683)
* re-add vary header fixes #580 * add Const to enable/disable `Vary` header * lets start with default "off"
1 parent 20adc4c commit 3b21061

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ The plugin uses PHP Constants to enable, disable or change its default behaviour
121121
* `ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS` - Block incoming replies/comments/likes. Default: `false`.
122122
* `ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS` - Disable outgoing replies/comments/likes. Default: `false`.
123123
* `ACTIVITYPUB_SHARED_INBOX_FEATURE` - Enable the shared inbox. Default: `false`.
124+
* `ACTIVITYPUB_SEND_VARY_HEADER` - Enable to send the `Vary: Accept` header. Default: `false`.
124125

125126
### Where can you manage your followers? ###
126127

@@ -140,7 +141,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
140141
* Fixed: Remove old/abandoned Crons
141142
* Added: Various endpoints for the "Enable Mastodon Apps" plugin
142143
* Added: Event Objects
143-
* Improved: Post-Type support
144+
* Added: Vary-Header support behind feature flag
144145

145146
### 2.0.1 ###
146147

activitypub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
3737
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
3838
\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
39+
\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
3940

4041
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
4142
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

includes/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ function is_activitypub_request() {
312312
}
313313
}
314314

315+
// Check if header already sent.
316+
if ( ! \headers_sent() && ACTIVITYPUB_SEND_VARY_HEADER ) {
317+
// Send Vary header for Accept header.
318+
\header( 'Vary: Accept' );
319+
}
320+
315321
// One can trigger an ActivityPub request by adding ?activitypub to the URL.
316322
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.VariableRedeclaration
317323
global $wp_query;

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ The plugin uses PHP Constants to enable, disable or change its default behaviour
121121
* `ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS` - Block incoming replies/comments/likes. Default: `false`.
122122
* `ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS` - Disable outgoing replies/comments/likes. Default: `false`.
123123
* `ACTIVITYPUB_SHARED_INBOX_FEATURE` - Enable the shared inbox. Default: `false`.
124+
* `ACTIVITYPUB_SEND_VARY_HEADER` - Enable to send the `Vary: Accept` header. Default: `false`.
124125

125126
= Where can you manage your followers? =
126127

@@ -140,7 +141,7 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu
140141
* Fixed: Remove old/abandoned Crons
141142
* Added: Various endpoints for the "Enable Mastodon Apps" plugin
142143
* Added: Event Objects
143-
* Improved: Post-Type support
144+
* Added: Vary-Header support behind feature flag
144145

145146
= 2.0.1 =
146147

0 commit comments

Comments
 (0)