From 67bd3f38ac9c26fda18f9d9ee5b4c1788ab656de Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 10 Jun 2014 11:55:27 -0700 Subject: [PATCH] * lib/webrick/httpresponse.rb: unset content-length header when responding to HEAD requests. * test/webrick/test_httpresponse.rb: tests for above --- lib/webrick/httpresponse.rb | 2 +- test/webrick/test_httpresponse.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index 9656f81..959aea2 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -240,7 +240,7 @@ module WEBrick end # Determine the message length (RFC2616 -- 4.4 Message Length) - if @status == 304 || @status == 204 || HTTPStatus::info?(@status) + if @status == 304 || @status == 204 || HTTPStatus::info?(@status) || @request_method == 'HEAD' @header.delete('content-length') @body = "" elsif chunked? diff --git a/test/webrick/test_httpresponse.rb b/test/webrick/test_httpresponse.rb index c9fb4ff..3105f4a 100644 --- a/test/webrick/test_httpresponse.rb +++ b/test/webrick/test_httpresponse.rb @@ -137,5 +137,13 @@ module WEBrick r.binmode assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read end + + def test_head_does_not_return_body + res.request_method = 'HEAD' + res.body = 'ignored' + res.setup_header + assert_equal nil, res.header['content-length'] + assert_equal '', res.body + end end end -- 1.9.3