diff options
-rw-r--r-- | src/cow_http_hd.erl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index b9bfc56..441cd1d 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -472,6 +472,28 @@ parse_accept_encoding(Encoding) -> conneg_list(Encoding, []). -ifdef(TEST). +accept_encoding() -> + ?LET({E, W}, + {token(), weight()}, + {E, W, iolist_to_binary([E, case W of + undefined -> []; + _ -> [<<";q=">>, qvalue_to_iodata(W)] + end])} + ). + +prop_parse_accept_encoding() -> + ?FORALL(L, + non_empty(list(accept_encoding())), + begin + << _, AcceptEncoding/binary >> = iolist_to_binary([[$,, A] || {_, _, A} <- L]), + ResL = parse_accept_encoding(AcceptEncoding), + CheckedL = [begin + ResE =:= ?INLINE_LOWERCASE_BC(E) + andalso (ResW =:= W orelse (W =:= undefined andalso ResW =:= 1000)) + end || {{E, W, _}, {ResE, ResW}} <- lists:zip(L, ResL)], + [true] =:= lists:usort(CheckedL) + end). + parse_accept_encoding_test_() -> Tests = [ {<<>>, []}, |