Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionDispatch::SSL should keep original header's behavior #20672

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
* Fix to keep original header instance in `ActionDispatch::SSL`

`ActionDispatch::SSL` changes headers to `Hash`.
So some headers will be broken if there are some middlewares
on `ActionDispatch::SSL` and if it uses `Rack::Utils::HeaderHash`.

*Fumiaki Matsushima*

* Fix rake routes not showing the right format when
nesting multiple routes.

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(env)

if request.ssl?
status, headers, body = @app.call(env)
headers = hsts_headers.merge(headers)
headers.reverse_merge!(hsts_headers)
flag_cookies_as_secure!(headers)
[status, headers, body]
else
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/ssl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,15 @@ def test_redirect_to_secure_subdomain_when_on_deep_subdomain
assert_equal "https://example.co.uk/path?key=value",
response.headers['Location']
end

def test_keeps_original_headers_behavior
headers = Rack::Utils::HeaderHash.new(
"Content-Type" => "text/html",
"Connection" => ["close"]
)
self.app = ActionDispatch::SSL.new(lambda { |env| [200, headers, ["OK"]] })

get "https://example.org/"
assert_equal "close", response.headers["Connection"]
end
end