Skip to content

Commit

Permalink
[ruby/webrick] 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

ruby/webrick@069e9b1908
  • Loading branch information
jeremyevans authored and hsbt committed Nov 13, 2020
1 parent 6325866 commit 957efa9
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
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
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 957efa9

Please sign in to comment.