aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_rest.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-06 17:33:03 +0200
committerLoïc Hoguin <[email protected]>2016-06-06 17:33:03 +0200
commit6d6355723529ed3423c3d8b3c3ca9a29089e9f23 (patch)
tree7514f574f703fece2b3e8ccd0072cc3a6e3a7a03 /src/cowboy_rest.erl
parent68c57430daefd9a397c6c30d2168c4058409d74e (diff)
downloadcowboy-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.erl10
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);