mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:53:41 +08:00
9ac6f1d3bb
By default, Rails only includes the Vary:Accept header in responses when the Accept: header is included in the request. This means that proxies/browsers may cache a response to a request with a missing Accept header, and then later serve that cached version for a request which **does** supply the Accept header. This can lead to some very unexpected behavior in browsers. This commit adds the Vary:Accept header for all requests, even if the Accept header is not present in the request. If a format parameter (e.g. `.json` suffix) is included in the path, then the Accept header is still omitted. (The format parameter takes precedence over any Accept: header, so the response is no longer varies based on the Accept header)
8 lines
146 B
Ruby
8 lines
146 B
Ruby
# frozen_string_literal: true
|
|
|
|
module VaryHeader
|
|
def ensure_vary_header
|
|
response.headers['Vary'] ||= 'Accept' if !params[:format]
|
|
end
|
|
end
|