Skip to content

Commit 45c90b7

Browse files
committed
Rack spec requires mutable headers
The rack spec requires the header object to be an unfrozen hash. https://github.com/rack/rack/blob/c8e98221830a0b972b1dc19f3b6784f65197f444/SPEC.rdoc?plain=1#L240 Rack::ETag was buffering and making a copy of the response, so the freeze was not effective anyway. Plus we are freezing the hash too early, preventing middlewares from modifying it. It causes crash with gems like rack-livereload. I started having crashes on some pages (like the internal http://localhost:3000/rails/info/routes) because of rack-livereload hitting the frozen hash after the rack 3 upgrade. Also we're not consistent with the protection. We're not preventing users from adding cookies. The cookie jar is already flushed, therefore it doesn't try to change the headers and never triggers the frozen hash error.
1 parent bb8f1cf commit 45c90b7

File tree

2 files changed

+0
-31
lines changed

2 files changed

+0
-31
lines changed

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ def before_sending
462462
# our last chance.
463463
commit! unless committed?
464464

465-
@headers.freeze
466465
@request.commit_cookie_jar! unless committed?
467466
end
468467

actionpack/test/dispatch/live_response_test.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,36 +86,6 @@ def test_content_length_is_removed
8686
@response.stream.write "omg"
8787
assert_nil @response.headers["Content-Length"]
8888
end
89-
90-
def test_headers_cannot_be_written_after_web_server_reads
91-
@response.stream.write "omg"
92-
latch = Concurrent::CountDownLatch.new
93-
94-
t = Thread.new {
95-
@response.each do
96-
latch.count_down
97-
end
98-
}
99-
100-
latch.wait
101-
assert_predicate @response.headers, :frozen?
102-
assert_raises(FrozenError) do
103-
@response.headers["Content-Length"] = "zomg"
104-
end
105-
106-
@response.stream.close
107-
t.join
108-
end
109-
110-
def test_headers_cannot_be_written_after_close
111-
@response.stream.close
112-
# we can add data until it's actually written, which happens on `each`
113-
@response.each { |x| }
114-
115-
assert_raises(FrozenError) do
116-
@response.headers["Content-Length"] = "zomg"
117-
end
118-
end
11989
end
12090
end
12191
end

0 commit comments

Comments
 (0)