diff --git a/app/controllers/concerns/caching_headers.rb b/app/controllers/concerns/caching_headers.rb index c2f07468a..95e03fdf2 100644 --- a/app/controllers/concerns/caching_headers.rb +++ b/app/controllers/concerns/caching_headers.rb @@ -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. diff --git a/spec/requests/stories_index_spec.rb b/spec/requests/stories_index_spec.rb index c3606e855..fc57ebe5a 100644 --- a/spec/requests/stories_index_spec.rb +++ b/spec/requests/stories_index_spec.rb @@ -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)