]> cat aescling's git repositories - mastodon.git/commitdiff
Fix caching headers in ActivityPub endpoints (#11331)
authorThibG <thib@sitedethib.com>
Tue, 16 Jul 2019 22:00:39 +0000 (00:00 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 16 Jul 2019 22:00:39 +0000 (00:00 +0200)
* Fix reverse-proxy caching in public fetch mode

* Fix caching in ActivityPub-specific controllers

app/controllers/activitypub/base_controller.rb [new file with mode: 0644]
app/controllers/activitypub/collections_controller.rb
app/controllers/activitypub/outboxes_controller.rb
app/controllers/activitypub/replies_controller.rb
app/controllers/application_controller.rb

diff --git a/app/controllers/activitypub/base_controller.rb b/app/controllers/activitypub/base_controller.rb
new file mode 100644 (file)
index 0000000..a3b5c4d
--- /dev/null
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class ActivityPub::BaseController < Api::BaseController
+  private
+
+  def set_cache_headers
+    response.headers['Vary'] = 'Signature' if authorized_fetch_mode?
+  end
+end
index 035467f41747913216179c653aa4502e09b7b1ba..fa925b204e67acb9d56e9ebafd9629a793e8fe1c 100644 (file)
@@ -1,6 +1,6 @@
 # frozen_string_literal: true
 
-class ActivityPub::CollectionsController < Api::BaseController
+class ActivityPub::CollectionsController < ActivityPub::BaseController
   include SignatureVerification
   include AccountOwnedConcern
 
index cdfd28ba8430be943d02940d06fd5579888f0822..891756b7e6a8c7c5c2fd58e905978c5a47c079b6 100644 (file)
@@ -1,6 +1,6 @@
 # frozen_string_literal: true
 
-class ActivityPub::OutboxesController < Api::BaseController
+class ActivityPub::OutboxesController < ActivityPub::BaseController
   LIMIT = 20
 
   include SignatureVerification
index 020c077ab0c0b02a1259bde52a1961c0f3fcff6c..ab755ed4e6e45448746b61696b33b3e1d65437d2 100644 (file)
@@ -1,6 +1,6 @@
 # frozen_string_literal: true
 
-class ActivityPub::RepliesController < Api::BaseController
+class ActivityPub::RepliesController < ActivityPub::BaseController
   include SignatureAuthentication
   include Authorization
   include AccountOwnedConcern
index 16e7d70a37c2a51c4c08ea6cabeb8d49d026aa71..26f3b1def5ba9795286a325bbe616402455d8085 100644 (file)
@@ -160,6 +160,6 @@ class ApplicationController < ActionController::Base
   end
 
   def set_cache_headers
-    response.headers['Vary'] = 'Accept, Signature'
+    response.headers['Vary'] = public_fetch_mode? ? 'Accept' : 'Accept, Signature'
   end
 end