mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add REQUEST_PATH on parse error message (#1831)
``` 2019-07-01 21:31:08 +0200: HTTP parse error, malformed request (127.0.0.1/plop): #<Puma::HttpParserError: HTTP element QUERY_STRING is longer than the (1024 * 10) allowed length (was 20481)> ``` ref https://github.com/puma/puma/issues/1768
This commit is contained in:
parent
70b28bb5dd
commit
0cb108828e
2 changed files with 25 additions and 1 deletions
|
@ -93,7 +93,10 @@ module Puma
|
|||
# parsing exception.
|
||||
#
|
||||
def parse_error(server, env, error)
|
||||
@stderr.puts "#{Time.now}: HTTP parse error, malformed request (#{env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR]}): #{error.inspect}\n---\n"
|
||||
@stderr.puts "#{Time.now}: HTTP parse error, malformed request " \
|
||||
"(#{env[HTTP_X_FORWARDED_FOR] || env[REMOTE_ADDR]}#{env[REQUEST_PATH]}): " \
|
||||
"#{error.inspect}" \
|
||||
"\n---\n"
|
||||
end
|
||||
|
||||
# An SSL error has occurred.
|
||||
|
|
|
@ -164,4 +164,25 @@ class TestEvents < Minitest::Test
|
|||
|
||||
assert_equal "-> ready", out
|
||||
end
|
||||
|
||||
def test_parse_error
|
||||
port = 0
|
||||
host = "127.0.0.1"
|
||||
app = proc { |env| [200, {"Content-Type" => "plain/text"}, ["hello\n"]] }
|
||||
events = Puma::Events.strings
|
||||
server = Puma::Server.new app, events
|
||||
|
||||
server.add_tcp_listener host, port
|
||||
server.run
|
||||
|
||||
sock = TCPSocket.new host, server.connected_port
|
||||
path = "/"
|
||||
params = "a"*1024*10
|
||||
|
||||
sock << "GET #{path}?a=#{params} HTTP/1.1\r\nConnection: close\r\n\r\n"
|
||||
sock.read
|
||||
sleep 0.1 # important so that the previous data is sent as a packet
|
||||
assert_match %r!HTTP parse error, malformed request \(#{path}\)!, events.stderr.string
|
||||
server.stop(true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue