diff options
author | Loïc Hoguin <[email protected]> | 2016-06-06 17:33:03 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-06-06 17:33:03 +0200 |
commit | 6d6355723529ed3423c3d8b3c3ca9a29089e9f23 (patch) | |
tree | 7514f574f703fece2b3e8ccd0072cc3a6e3a7a03 /src/cowboy_rest.erl | |
parent | 68c57430daefd9a397c6c30d2168c4058409d74e (diff) | |
download | cowboy-6d6355723529ed3423c3d8b3c3ca9a29089e9f23.tar.gz cowboy-6d6355723529ed3423c3d8b3c3ca9a29089e9f23.tar.bz2 cowboy-6d6355723529ed3423c3d8b3c3ca9a29089e9f23.zip |
REST: If-None-Match uses weak Etag comparison
Was badly implemented previously.
Diffstat (limited to 'src/cowboy_rest.erl')
-rw-r--r-- | src/cowboy_rest.erl | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl index d28c8e9..670e74b 100644 --- a/src/cowboy_rest.erl +++ b/src/cowboy_rest.erl @@ -741,7 +741,7 @@ if_none_match(Req, State, EtagsList) -> undefined -> precondition_failed(Req2, State2); Etag -> - case lists:member(Etag, EtagsList) of + case is_weak_match(Etag, EtagsList) of true -> precondition_is_head_get(Req2, State2); false -> if_modified_since_exists(Req2, State2) end @@ -750,6 +750,14 @@ if_none_match(Req, State, EtagsList) -> error_terminate(Req, State, Class, Reason, generate_etag) end. +%% Weak Etag comparison: only check the opaque tag. +is_weak_match(_, []) -> + false; +is_weak_match({_, Tag}, [{_, Tag}|_]) -> + true; +is_weak_match(Etag, [_|Tail]) -> + is_weak_match(Etag, Tail). + precondition_is_head_get(Req, State=#state{method=Method}) when Method =:= <<"HEAD">>; Method =:= <<"GET">> -> not_modified(Req, State); |