You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2019/03/06 15:01:43 UTC

[couchdb] branch weak-etag-comparison created (now f95a539)

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a change to branch weak-etag-comparison
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at f95a539  Ignore weak ETag part

This branch includes the following new commits:

     new f95a539  Ignore weak ETag part

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Ignore weak ETag part

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch weak-etag-comparison
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f95a539508062143c4dd194ceda5a81a8344a126
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Mar 6 14:58:23 2019 +0000

    Ignore weak ETag part
    
    Some load balancer configurations (HAproxy with compression enabled is
    the motivating example) will add W/ to our response ETags if they
    modify the response before sending it to the client.
    
    as per rfc7232 section 3.2;
    
    "A recipient MUST use the weak comparison function when comparing
    entity-tags for If-None-Match (Section 2.3.2), since weak entity-tags
    can be used for cache validation even if there have been changes to
    the representation data."
    
    This change improves our ETag checking toward RFC compliance.
---
 src/chttpd/src/chttpd.erl | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index ac371a2..1e1d638 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 ->