Skip edge caching for private forems (#10817)

* Skip edge caching for private forems

* Add test

* Update spec/requests/stories_index_spec.rb

* Adjust comment

* Also check other cache-related headers
This commit is contained in:
Ben Halpern 2020-10-13 13:36:20 -04:00 committed by GitHub
parent 7ce3b8abd2
commit bc248f17e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -17,6 +17,8 @@ module CachingHeaders
stale_while_revalidate: nil,
stale_if_error: 26_400
)
return unless SiteConfig.public # Only public forems should be edge-cached based on current functionality.
request.session_options[:skip] = true # no cookies
response.headers["Cache-Control"] = "public, no-cache" # Used only by Fastly.

View file

@ -104,6 +104,16 @@ RSpec.describe "StoriesIndex", type: :request do
expect(response.body).to include(CGI.escapeHTML(listing.title))
end
it "does not set cache-related headers if private" do
allow(SiteConfig).to receive(:public).and_return(false)
get "/"
expect(response.status).to eq(200)
expect(response.headers["X-Accel-Expires"]).to eq(nil)
expect(response.headers["Cache-Control"]).not_to eq("public, no-cache")
expect(response.headers["Surrogate-Key"]).to eq(nil)
end
it "sets Fastly Surrogate-Key headers" do
get "/"
expect(response.status).to eq(200)