Patchwork D2785: hgweb: inline caching() and port to modern mechanisms

login
register
mail settings
Submitter phabricator
Date March 12, 2018, 9:33 p.m.
Message ID <1a76c2aff1ad8acf7fb08fd005c6fb35@localhost.localdomain>
Download mbox | patch
Permalink /patch/29362/
State Not Applicable
Headers show

Comments

phabricator - March 12, 2018, 9:33 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG7ad6a275316f: hgweb: inline caching() and port to modern mechanisms (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2785?vs=6846&id=6921

REVISION DETAIL
  https://phab.mercurial-scm.org/D2785

AFFECTED FILES
  mercurial/hgweb/common.py
  mercurial/hgweb/hgweb_mod.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -18,7 +18,6 @@ 
     HTTP_NOT_MODIFIED,
     HTTP_OK,
     HTTP_SERVER_ERROR,
-    caching,
     cspvalues,
     permhooks,
 )
@@ -388,7 +387,13 @@ 
             # Don't enable caching if using a CSP nonce because then it wouldn't
             # be a nonce.
             if rctx.configbool('web', 'cache') and not rctx.nonce:
-                caching(self, wsgireq) # sets ETag header or raises NOT_MODIFIED
+                tag = 'W/"%d"' % self.mtime
+                if req.headers.get('If-None-Match') == tag:
+                    raise ErrorResponse(HTTP_NOT_MODIFIED)
+
+                wsgireq.headers.append((r'ETag', pycompat.sysstr(tag)))
+                res.headers['ETag'] = tag
+
             if cmd not in webcommands.__all__:
                 msg = 'no such method: %s' % cmd
                 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -214,12 +214,6 @@ 
             config("ui", "username") or
             encoding.environ.get("EMAIL") or "")
 
-def caching(web, req):
-    tag = r'W/"%d"' % web.mtime
-    if req.env.get('HTTP_IF_NONE_MATCH') == tag:
-        raise ErrorResponse(HTTP_NOT_MODIFIED)
-    req.headers.append(('ETag', tag))
-
 def cspvalues(ui):
     """Obtain the Content-Security-Policy header and nonce value.