diff mercurial/hgweb/common.py @ 12183:f64b416b0ac8

hgweb: support very simple caching model (issue1845)
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 08 Sep 2010 15:23:48 +0200
parents d6512b3e9ac0
children 14f3795a5ed7
line wrap: on
line diff
--- a/mercurial/hgweb/common.py	Wed Sep 08 15:11:35 2010 +0200
+++ b/mercurial/hgweb/common.py	Wed Sep 08 15:23:48 2010 +0200
@@ -9,6 +9,7 @@
 import errno, mimetypes, os
 
 HTTP_OK = 200
+HTTP_NOT_MODIFIED = 304
 HTTP_BAD_REQUEST = 400
 HTTP_UNAUTHORIZED = 401
 HTTP_FORBIDDEN = 403
@@ -152,3 +153,9 @@
     return (config("web", "contact") or
             config("ui", "username") or
             os.environ.get("EMAIL") or "")
+
+def caching(web, req):
+    tag = str(web.mtime)
+    if req.env.get('HTTP_IF_NONE_MATCH') == tag:
+        raise ErrorResponse(HTTP_NOT_MODIFIED)
+    req.headers.append(('ETag', tag))