mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
webrick/httprequest: raise correct exception
"BadRequest" alone does not resolve correctly, it is in the HTTPStatus namespace. * lib/webrick/httprequest.rb (read_chunked): use correct exception * test/webrick/test_httpserver.rb (test_eof_in_chunk): new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
89450a80fc
commit
6db6eb572b
2 changed files with 18 additions and 1 deletions
|
@ -511,7 +511,7 @@ module WEBrick
|
|||
while chunk_size > 0
|
||||
data = read_data(socket, chunk_size) # read chunk-data
|
||||
if data.nil? || data.bytesize != chunk_size
|
||||
raise BadRequest, "bad chunk data size."
|
||||
raise HTTPStatus::BadRequest, "bad chunk data size."
|
||||
end
|
||||
read_line(socket) # skip CRLF
|
||||
block.call(data)
|
||||
|
|
|
@ -458,4 +458,21 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
|
|||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_eof_in_chunk
|
||||
log_tester = lambda do |log, access_log|
|
||||
assert_equal 1, log.size
|
||||
assert log[0].include?('ERROR bad chunk data size')
|
||||
end
|
||||
TestWEBrick.start_httpserver({}, log_tester){|server, addr, port, log|
|
||||
server.mount_proc('/', ->(req, res) { res.body = req.body })
|
||||
TCPSocket.open(addr, port) do |c|
|
||||
c.write("POST / HTTP/1.1\r\nHost: example.com\r\n" \
|
||||
"Transfer-Encoding: chunked\r\n\r\n5\r\na")
|
||||
c.shutdown(Socket::SHUT_WR) # trigger EOF in server
|
||||
res = c.read
|
||||
assert_match %r{\AHTTP/1\.1 400 }, res
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue