diff options
author | Loïc Hoguin <[email protected]> | 2014-12-15 16:48:58 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-15 16:48:58 +0200 |
commit | c1af15e981801b6baf616f12dc3ddd944a30e4c5 (patch) | |
tree | efb9eb27c4f7095c1417309dc41fa0e10332872d | |
parent | f83befd47d74b739560b2595ea920fa88abff62f (diff) | |
download | cowlib-c1af15e981801b6baf616f12dc3ddd944a30e4c5.tar.gz cowlib-c1af15e981801b6baf616f12dc3ddd944a30e4c5.tar.bz2 cowlib-c1af15e981801b6baf616f12dc3ddd944a30e4c5.zip |
Add a property for cow_http_hd:parse_accept_encoding/1
-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 = [ {<<>>, []}, |