Skip to content

Commit db33424

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Fix caching headers in ActivityPub endpoints (mastodon#11331)
* Fix reverse-proxy caching in public fetch mode * Fix caching in ActivityPub-specific controllers
1 parent c0e4a25 commit db33424

5 files changed

Lines changed: 13 additions & 4 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
class ActivityPub::BaseController < Api::BaseController
4+
private
5+
6+
def set_cache_headers
7+
response.headers['Vary'] = 'Signature' if authorized_fetch_mode?
8+
end
9+
end

app/controllers/activitypub/collections_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class ActivityPub::CollectionsController < Api::BaseController
3+
class ActivityPub::CollectionsController < ActivityPub::BaseController
44
include SignatureVerification
55
include AccountOwnedConcern
66

app/controllers/activitypub/outboxes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class ActivityPub::OutboxesController < Api::BaseController
3+
class ActivityPub::OutboxesController < ActivityPub::BaseController
44
LIMIT = 20
55

66
include SignatureVerification

app/controllers/activitypub/replies_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class ActivityPub::RepliesController < Api::BaseController
3+
class ActivityPub::RepliesController < ActivityPub::BaseController
44
include SignatureAuthentication
55
include Authorization
66
include AccountOwnedConcern

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,6 @@ def render_cached_json(cache_key, **options)
160160
end
161161

162162
def set_cache_headers
163-
response.headers['Vary'] = 'Accept, Signature'
163+
response.headers['Vary'] = public_fetch_mode? ? 'Accept' : 'Accept, Signature'
164164
end
165165
end

0 commit comments

Comments
 (0)