Skip to content

Commit 011f655

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Explicitly disable storage of REST API results (mastodon#10655)
Fixes mastodon#10652
1 parent 01fa708 commit 011f655

5 files changed

Lines changed: 11 additions & 0 deletions

File tree

app/controllers/api/base_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Api::BaseController < ApplicationController
99
skip_before_action :store_current_location
1010
skip_before_action :check_user_permissions
1111

12+
before_action :set_cache_headers
13+
1214
protect_from_forgery with: :null_session
1315

1416
rescue_from ActiveRecord::RecordInvalid, Mastodon::ValidationError do |e|
@@ -88,4 +90,8 @@ def render_empty
8890
def authorize_if_got_token!(*scopes)
8991
doorkeeper_authorize!(*scopes) if doorkeeper_token
9092
end
93+
94+
def set_cache_headers
95+
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
96+
end
9197
end

app/controllers/api/v1/custom_emojis_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
class Api::V1::CustomEmojisController < Api::BaseController
44
respond_to :json
55

6+
skip_before_action :set_cache_headers
7+
68
def index
79
render_cached_json('api:v1:custom_emojis', expires_in: 1.minute) do
810
ActiveModelSerializers::SerializableResource.new(CustomEmoji.local.where(disabled: false), each_serializer: REST::CustomEmojiSerializer)

app/controllers/api/v1/instances/activity_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class Api::V1::Instances::ActivityController < Api::BaseController
44
before_action :require_enabled_api!
5+
skip_before_action :set_cache_headers
56

67
respond_to :json
78

app/controllers/api/v1/instances/peers_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class Api::V1::Instances::PeersController < Api::BaseController
44
before_action :require_enabled_api!
5+
skip_before_action :set_cache_headers
56

67
respond_to :json
78

app/controllers/api/v1/instances_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class Api::V1::InstancesController < Api::BaseController
44
respond_to :json
5+
skip_before_action :set_cache_headers
56

67
def show
78
render_cached_json('api:v1:instances', expires_in: 5.minutes) do

0 commit comments

Comments
 (0)