FIX: Bypass AnonymousCache for /srv/status route. (#11491)

`/srv/status` routes should not be cached at all. Also, we want to
decouple the route from Redis which `AnonymouseCache` relies on. The
`/srv/status` should continue to return a success response even if Redis
is down.
This commit is contained in:
Alan Guo Xiang Tan 2020-12-16 13:47:46 +08:00 committed by GitHub
parent 89bf64c0bf
commit 38b6b098bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -163,6 +163,7 @@ module Middleware
def no_cache_bypass
request = Rack::Request.new(@env)
request.cookies['_bypass_cache'].nil? &&
(request.path != '/srv/status') &&
request[Auth::DefaultCurrentUserProvider::API_KEY].nil? &&
@env[Auth::DefaultCurrentUserProvider::USER_API_KEY].nil?
end

View File

@ -26,6 +26,10 @@ describe Middleware::AnonymousCache do
it "is false if it has an auth cookie" do
expect(new_helper("HTTP_COOKIE" => "jack=1; _t=#{"1" * 32}; jill=2").cacheable?).to eq(false)
end
it "is false for srv/status routes" do
expect(new_helper("PATH_INFO" => "/srv/status").cacheable?).to eq(false)
end
end
context "per theme cache" do