From 3b85b808ae3cc48d19b71b72869ee59c25e70b00 Mon Sep 17 00:00:00 2001 From: Marcos Ferreira Date: Mon, 23 Dec 2019 22:31:47 -0300 Subject: Ignore malformed accept-encoding headers in cowboy_compress_h --- src/cowboy_compress_h.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cowboy_compress_h.erl b/src/cowboy_compress_h.erl index e9824ba..374cb6a 100644 --- a/src/cowboy_compress_h.erl +++ b/src/cowboy_compress_h.erl @@ -71,9 +71,10 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) -> %% Internal. %% Check if the client supports decoding of gzip responses. +%% +%% A malformed accept-encoding header is ignored (no compression). 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 +88,9 @@ check_req(Req) -> _ -> #state{compress=gzip} end + catch + _:_ -> + #state{compress=undefined} end. %% Do not compress responses that contain the content-encoding header. -- cgit v1.2.3