Skip to content

Commit

Permalink
Make 400/431 log message less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Mar 17, 2018
1 parent 2c81430 commit 5b6c4ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions lib/plug/adapters/cowboy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@ defmodule Plug.Adapters.Cowboy do
defp onresponse(status, _headers, _body, request) do
if status == 400 and empty_headers?(request) do
Logger.error("""
Cowboy returned 400 and there are no headers in the connection.
Cowboy returned 400 because it was unable to parse the request headers.
This may happen if Cowboy is unable to parse the request headers,
for example, because there are too many headers or the header name
or value are too large (such as a large cookie).
This may happen because there are no headers, or there are too many headers
or the header name or value are too large (such as a large cookie).
You can customize those values when configuring your http/https
server. The configuration option and default values are shown below:
Expand Down
17 changes: 8 additions & 9 deletions lib/plug/adapters/cowboy2/bad_response_check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ defmodule Plug.Adapters.Cowboy2.BadResponseCheck do
case reason do
{:connection_error, :limit_reached, _} ->
Logger.error("""
Cowboy returned 431 and there are no headers in the connection.
Cowboy returned 431 because it was unable to parse the request headers.
This may happen if Cowboy is unable to parse the request headers,
for example, because there are too many headers or the header name
or value are too large (such as a large cookie).
This may happen because there are no headers, or there are too many headers
or the header name or value are too large (such as a large cookie).
You can customize those values when configuring your http/https
server. The configuration option and default values are shown below:
protocol_options: [
max_header_name_length: 64,
max_header_value_length: 4096,
max_headers: 100
]
protocol_options: [
max_header_name_length: 64,
max_header_value_length: 4096,
max_headers: 100
]
""")

_ ->
Expand Down
2 changes: 1 addition & 1 deletion test/plug/adapters/cowboy/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ defmodule Plug.Adapters.Cowboy.ConnTest do
assert {200, _, _} = request(:get, "/headers", [{"foo", "bar"}, {"baz", "bat"}])
end)

assert log =~ "Cowboy returned 400 and there are no headers in the connection"
assert log =~ "Cowboy returned 400 because it was unable to parse the request headers"
end

def send_200(conn) do
Expand Down
2 changes: 1 addition & 1 deletion test/plug/adapters/cowboy2/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ defmodule Plug.Adapters.Cowboy2.ConnTest do
response = request(:get, "/headers", [{"cookie", cookie}])
assert match?({431, _, _}, response) or match?({:error, :closed}, response)
assert {200, _, _} = request(:get, "/headers", [{"foo", "bar"}, {"baz", "bat"}])
end) =~ "Cowboy returned 431 and there are no headers in the connection"
end) =~ "Cowboy returned 431 because it was unable to parse the request headers"
end

def send_200(conn) do
Expand Down

0 comments on commit 5b6c4ba

Please sign in to comment.