summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2019-03-06 18:43:02 +0000
committerGitHub <noreply@github.com>2019-03-06 18:43:02 +0000
commit8ef42f7241f8788afc1b6e7255ce78ce5d5ea5c3 (patch)
tree2d77128c497a6079ddec33b6cc4d7c50f665ebbf
parentaee2fd9859c14aed1cb28f458a846064c58cf782 (diff)
parentc151a321da0df18fb563b9cd09ba64e56e540e38 (diff)
downloadcouchdb-8ef42f7241f8788afc1b6e7255ce78ce5d5ea5c3.tar.gz
Merge pull request #1971 from apache/weak-etag-comparison
Ignore weak ETag part
-rw-r--r--src/chttpd/src/chttpd.erl8
-rw-r--r--test/javascript/tests/etags_head.js4
2 files changed, 11 insertions, 1 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index ac371a2e5..1e1d638be 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -693,10 +693,16 @@ etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) ->
etag_match(Req, binary_to_list(CurrentEtag));
etag_match(Req, CurrentEtag) ->
- EtagsToMatch = string:tokens(
+ EtagsToMatch0 = string:tokens(
chttpd:header_value(Req, "If-None-Match", ""), ", "),
+ EtagsToMatch = lists:map(fun strip_weak_prefix/1, EtagsToMatch0),
lists:member(CurrentEtag, EtagsToMatch).
+strip_weak_prefix([$W, $/ | Etag]) ->
+ Etag;
+strip_weak_prefix(Etag) ->
+ Etag.
+
etag_respond(Req, CurrentEtag, RespFun) ->
case etag_match(Req, CurrentEtag) of
true ->
diff --git a/test/javascript/tests/etags_head.js b/test/javascript/tests/etags_head.js
index ab5476921..9faca4af6 100644
--- a/test/javascript/tests/etags_head.js
+++ b/test/javascript/tests/etags_head.js
@@ -63,6 +63,10 @@ couchTests.etags_head = function(debug) {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
+ xhr = CouchDB.request("GET", "/" + db_name + "/1", {
+ headers: {"if-none-match": "W/" + etag}
+ });
+ T(xhr.status == 304);
// fail to delete a doc
xhr = CouchDB.request("DELETE", "/" + db_name + "/1", {