mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Avoid crashing in cowboy_req on invalid Accept-Encoding header
Certain clients send malformed Accept-Encoding headers, which causes cowboy_req to crash is compression is enabled.
This commit is contained in:
parent
a55c20c4ef
commit
ba1eca6b97
1 changed files with 30 additions and 25 deletions
|
@ -1021,7 +1021,8 @@ reply(Status, Headers, Body, Req=#http_req{
|
|||
reply_may_compress(Status, Headers, Body, Req,
|
||||
RespHeaders, HTTP11Headers, Method) ->
|
||||
BodySize = iolist_size(Body),
|
||||
{ok, Encodings, Req2} = parse_header(<<"accept-encoding">>, Req),
|
||||
case parse_header(<<"accept-encoding">>, Req) of
|
||||
{ok, Encodings, Req2} ->
|
||||
CanGzip = (BodySize > 300)
|
||||
andalso (false =:= lists:keyfind(<<"content-encoding">>,
|
||||
1, Headers))
|
||||
|
@ -1048,6 +1049,10 @@ reply_may_compress(Status, Headers, Body, Req,
|
|||
false ->
|
||||
reply_no_compress(Status, Headers, Body, Req,
|
||||
RespHeaders, HTTP11Headers, Method, BodySize)
|
||||
end;
|
||||
{error, badarg} ->
|
||||
reply_no_compress(Status, Headers, Body, Req,
|
||||
RespHeaders, HTTP11Headers, Method, BodySize)
|
||||
end.
|
||||
|
||||
reply_no_compress(Status, Headers, Body, Req,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue