Skip to content

Commit 8cff7f3

Browse files
committed
Enabled chunked encoding if Transfer-Encoding: chunked header is set
Patch from Leonard Garvey. Fixes Ruby Bug 9986.
1 parent 0103fd5 commit 8cff7f3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/webrick/httpresponse.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def [](field)
142142
# Sets the response header +field+ to +value+
143143

144144
def []=(field, value)
145+
@chunked = value.to_s.downcase == 'chunked' if field.downcase == 'transfer-encoding'
145146
@header[field.downcase] = value.to_s
146147
end
147148

test/webrick/test_httpresponse.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def test_1xx_does_not_log_warnings
133133
assert_equal 0, logger.messages.length
134134
end
135135

136+
def test_200_chunked_does_not_set_content_length
137+
res.chunked = false
138+
res["Transfer-Encoding"] = 'chunked'
139+
res.setup_header
140+
assert_nil res.header.fetch('content-length', nil)
141+
end
142+
136143
def test_send_body_io
137144
IO.pipe {|body_r, body_w|
138145
body_w.write 'hello'

0 commit comments

Comments
 (0)