Skip to content

Commit

Permalink
Allow empty POST and PUT requests without content length
Browse files Browse the repository at this point in the history
RFC 7230 section 3.3.3 allows for this.

Fixes #30
  • Loading branch information
jeremyevans committed Jul 15, 2020
1 parent e693f50 commit e532e47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrick/httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def read_body(socket, block)
if @remaining_size > 0 && @socket.eof?
raise HTTPStatus::BadRequest, "invalid body size."
end
elsif BODY_CONTAINABLE_METHODS.member?(@request_method)
elsif BODY_CONTAINABLE_METHODS.member?(@request_method) && !@socket.eof
raise HTTPStatus::LengthRequired
end
return @body
Expand Down
12 changes: 12 additions & 0 deletions test/webrick/test_httprequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ def test_continue_not_sent
assert_equal l, msg.size
end

def test_empty_post
msg = <<-_end_of_message_
POST /path?foo=x;foo=y;foo=z;bar=1 HTTP/1.1
Host: test.ruby-lang.org:8080
Content-Type: application/x-www-form-urlencoded
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
req.body
end

def test_bad_messages
param = "foo=1;foo=2;foo=3;bar=x"
msg = <<-_end_of_message_
Expand Down

0 comments on commit e532e47

Please sign in to comment.