From 868568d1c11227319228ec4066c7017621b9f522 Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 27 Dec 2017 18:21:12 +0100 Subject: [PATCH] Make host_meta/webfinger replies cacheable (fixes #6100) (#6101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make host_meta/webfinger replies cacheable (fixes #6100) Drop common code for handling users and sessions as webfinger queries are very basic, public APIs. Also explicitly mark results as cacheable with “expires_in”. * Add “Vary: Accept” header for caching since content-negociation is used --- app/controllers/well_known/host_meta_controller.rb | 6 +++++- app/controllers/well_known/webfinger_controller.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/well_known/host_meta_controller.rb b/app/controllers/well_known/host_meta_controller.rb index 40f96eaa258..5fb70288a2a 100644 --- a/app/controllers/well_known/host_meta_controller.rb +++ b/app/controllers/well_known/host_meta_controller.rb @@ -1,15 +1,19 @@ # frozen_string_literal: true module WellKnown - class HostMetaController < ApplicationController + class HostMetaController < ActionController::Base include RoutingHelper + before_action { response.headers['Vary'] = 'Accept' } + def show @webfinger_template = "#{webfinger_url}?resource={uri}" respond_to do |format| format.xml { render content_type: 'application/xrd+xml' } end + + expires_in(3.days, public: true) end end end diff --git a/app/controllers/well_known/webfinger_controller.rb b/app/controllers/well_known/webfinger_controller.rb index 5cc606808bf..28654b61d8c 100644 --- a/app/controllers/well_known/webfinger_controller.rb +++ b/app/controllers/well_known/webfinger_controller.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true module WellKnown - class WebfingerController < ApplicationController + class WebfingerController < ActionController::Base include RoutingHelper + before_action { response.headers['Vary'] = 'Accept' } + def show @account = Account.find_local!(username_from_resource) @@ -16,6 +18,8 @@ module WellKnown render content_type: 'application/xrd+xml' end end + + expires_in(3.days, public: true) rescue ActiveRecord::RecordNotFound head 404 end