diff --git lib/webrick/httpresponse.rb lib/webrick/httpresponse.rb index e897e8c..e20974e 100644 --- lib/webrick/httpresponse.rb +++ lib/webrick/httpresponse.rb @@ -181,7 +181,11 @@ module WEBrick # Will this response body be returned using chunked transfer-encoding? def chunked? - @chunked + if @header['transfer-encoding'] == 'chunked' + @chunked = true + else + @chunked + end end ## diff --git test/webrick/test_httpresponse.rb test/webrick/test_httpresponse.rb index 1f85a92..81b1268 100644 --- test/webrick/test_httpresponse.rb +++ test/webrick/test_httpresponse.rb @@ -47,6 +47,16 @@ module WEBrick assert_equal 0, logger.messages.length end + def test_200_chunked_does_not_set_content_length + res.body = 'hello' + res.status = 200 + res.chunked = false + res["Transfer-Encoding"] = 'chunked' + res.setup_header + + assert_nil res.header.fetch('content-length', nil) + end + def test_send_body_io IO.pipe {|body_r, body_w| body_w.write 'hello'