Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Router/RewriteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,22 @@ public function handle_accept_negotiation(): void {
return;
}

// Prevent shared caches (CDNs, reverse proxies) that don't honour
// Vary from storing this content-negotiation redirect and serving
// the 303 to every visitor regardless of their Accept header.
header('Cache-Control: private');

// Many WordPress page-cache plugins cache at the PHP level and may
// not vary by the Accept request header. Tell them explicitly not to
// cache this response. Sites with Vary-aware caching can disable this:
// add_filter( 'markdown_alternate_disable_page_cache_on_redirect', '__return_false' );
if ( apply_filters( 'markdown_alternate_disable_page_cache_on_redirect', true ) ) {
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', true );
}
do_action( 'litespeed_control_set_nocache', 'Content negotiation redirect' );
}

// 303 See Other: redirect to markdown URL with Vary for cache correctness.
header('Vary: Accept');
wp_safe_redirect($md_url, 303);
Expand Down