Skip to content

Commit

Permalink
Allow HTTP caching of json view of public statuses (mastodon#6115)
Browse files Browse the repository at this point in the history
* Allow HTTP caching of json view of public statuses

HTML views are not cached as they can contain private statuses as well

* Disable session cookies for ActivityPub json rendering of public toots
  • Loading branch information
ClearlyClaire authored and Gargron committed Jan 3, 2018
1 parent 0c98e8e commit 2d2474b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class StatusesController < ApplicationController
before_action :set_link_headers
before_action :check_account_suspension
before_action :redirect_to_original, only: [:show]
before_action { response.headers['Vary'] = 'Accept' }

def show
respond_to do |format|
Expand All @@ -25,6 +26,12 @@ def show
serializer: ActivityPub::NoteSerializer,
adapter: ActivityPub::Adapter,
content_type: 'application/activity+json'

# Allow HTTP caching for 3 minutes if the status is public
unless @stream_entry.hidden?
request.session_options[:skip] = true
expires_in(3.minutes, public: true)
end
end
end
end
Expand Down

0 comments on commit 2d2474b

Please sign in to comment.