0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Don't raise an error for malformed accept-encoding headers in compressed

This commit is contained in:
Marcos Ferreira 2019-12-23 22:31:47 -03:00
parent 63b17e4edf
commit 8ffbe073c2
No known key found for this signature in database
GPG key ID: 55332D1086F6114C
2 changed files with 23 additions and 2 deletions

View file

@ -72,8 +72,7 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
%% Check if the client supports decoding of gzip responses.
check_req(Req) ->
%% @todo Probably shouldn't unconditionally crash on failure.
case cowboy_req:parse_header(<<"accept-encoding">>, Req) of
try cowboy_req:parse_header(<<"accept-encoding">>, Req) of
%% Client doesn't support any compression algorithm.
undefined ->
#state{compress=undefined};
@ -87,6 +86,10 @@ check_req(Req) ->
_ ->
#state{compress=gzip}
end
catch
%% Don't raise an error because of malformed or unsupported accept-encoding headers.
exit:{request_error, {header, <<"accept-encoding">>}, _Reason} ->
#state{compress=undefined}
end.
%% Do not compress responses that contain the content-encoding header.

View file

@ -80,6 +80,24 @@ gzip_accept_encoding_no_gzip(Config) ->
{_, <<"100000">>} = lists:keyfind(<<"content-length">>, 1, Headers),
ok.
gzip_accept_encoding_not_supported(Config) ->
doc("Send not supported accept-encoding; get an uncompressed response."),
{200, Headers, _} = do_get("/reply/large",
[{<<"accept-encoding">>, <<"application/gzip">>}], Config),
false = lists:keyfind(<<"content-encoding">>, 1, Headers),
false = lists:keyfind(<<"vary">>, 1, Headers),
{_, <<"100000">>} = lists:keyfind(<<"content-length">>, 1, Headers),
ok.
gzip_accept_encoding_malformed(Config) ->
doc("Send malformed accept-encoding; get an uncompressed response."),
{200, Headers, _} = do_get("/reply/large",
[{<<"accept-encoding">>, <<";">>}], Config),
false = lists:keyfind(<<"content-encoding">>, 1, Headers),
false = lists:keyfind(<<"vary">>, 1, Headers),
{_, <<"100000">>} = lists:keyfind(<<"content-length">>, 1, Headers),
ok.
gzip_reply_content_encoding(Config) ->
doc("Reply with content-encoding header; get an uncompressed response."),
{200, Headers, _} = do_get("/reply/content-encoding",