Skip to content

Commit 069e9b1

Browse files
committed
Allow empty POST and PUT requests without content length
RFC 7230 section 3.3.3 allows for this. Fixes #30
1 parent fbe85b8 commit 069e9b1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/webrick/httprequest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def read_body(socket, block)
522522
if @remaining_size > 0 && @socket.eof?
523523
raise HTTPStatus::BadRequest, "invalid body size."
524524
end
525-
elsif BODY_CONTAINABLE_METHODS.member?(@request_method)
525+
elsif BODY_CONTAINABLE_METHODS.member?(@request_method) && !@socket.eof
526526
raise HTTPStatus::LengthRequired
527527
end
528528
return @body

test/webrick/test_httprequest.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ def test_continue_not_sent
425425
assert_equal l, msg.size
426426
end
427427

428+
def test_empty_post
429+
msg = <<-_end_of_message_
430+
POST /path?foo=x;foo=y;foo=z;bar=1 HTTP/1.1
431+
Host: test.ruby-lang.org:8080
432+
Content-Type: application/x-www-form-urlencoded
433+
434+
_end_of_message_
435+
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
436+
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
437+
req.body
438+
end
439+
428440
def test_bad_messages
429441
param = "foo=1;foo=2;foo=3;bar=x"
430442
msg = <<-_end_of_message_

0 commit comments

Comments
 (0)