Skip to content

Commit

Permalink
Add REQUEST_PATH on parse error message (#1831)
Browse files Browse the repository at this point in the history
```
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 #1768
  • Loading branch information
spk authored and nateberkopec committed Jul 27, 2019
1 parent 70b28bb commit 0cb1088
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/puma/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def format(str)
# 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.
Expand Down
21 changes: 21 additions & 0 deletions test/test_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,25 @@ def test_custom_log_formatter

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

0 comments on commit 0cb1088

Please sign in to comment.