before_action :set_cache_headers
def show
- expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode? && !(signed_request_account.present? && page_requested?))
+ if page_requested?
+ expires_in(1.minute, public: public_fetch_mode? && signed_request_account.nil?)
+ else
+ expires_in(3.minutes, public: public_fetch_mode?)
+ end
render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
end
def set_account
@account = params[:account_username].present? ? Account.find_local!(username_param) : Account.representative
end
+
+ def set_cache_headers
+ response.headers['Vary'] = 'Signature' if authorized_fetch_mode? || page_requested?
+ end
end
class WebfingerController < ActionController::Base
include RoutingHelper
- before_action { response.headers['Vary'] = 'Accept' }
before_action :set_account
before_action :check_account_suspension
end
def bad_request
+ expires_in(3.minutes, public: true)
head 400
end
def not_found
+ expires_in(3.minutes, public: true)
head 404
end
it_behaves_like 'cachable response'
+ it 'does not have a Vary header' do
+ expect(response.headers['Vary']).to be_nil
+ end
+
context 'when account is permanently suspended' do
before do
account.suspend!
it_behaves_like 'cachable response'
+ it 'returns Vary header with Signature' do
+ expect(response.headers['Vary']).to include 'Signature'
+ end
+
context 'when account is permanently suspended' do
before do
account.suspend!
end
it 'returns private Cache-Control header' do
- expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
+ expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
end
end
end
it 'returns private Cache-Control header' do
- expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
+ expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
end
end
end
it 'returns private Cache-Control header' do
- expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
+ expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
end
end
end
it 'returns private Cache-Control header' do
- expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
+ expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
end
end
end
expect(response).to have_http_status(200)
end
+ it 'does not set a Vary header' do
+ expect(response.headers['Vary']).to be_nil
+ end
+
it 'returns application/jrd+json' do
expect(response.media_type).to eq 'application/jrd+json'
end