Show More
@@ -9,6 +9,7 b'' | |||||
9 | import errno, mimetypes, os |
|
9 | import errno, mimetypes, os | |
10 |
|
10 | |||
11 | HTTP_OK = 200 |
|
11 | HTTP_OK = 200 | |
|
12 | HTTP_NOT_MODIFIED = 304 | |||
12 | HTTP_BAD_REQUEST = 400 |
|
13 | HTTP_BAD_REQUEST = 400 | |
13 | HTTP_UNAUTHORIZED = 401 |
|
14 | HTTP_UNAUTHORIZED = 401 | |
14 | HTTP_FORBIDDEN = 403 |
|
15 | HTTP_FORBIDDEN = 403 | |
@@ -152,3 +153,9 b' def get_contact(config):' | |||||
152 | return (config("web", "contact") or |
|
153 | return (config("web", "contact") or | |
153 | config("ui", "username") or |
|
154 | config("ui", "username") or | |
154 | os.environ.get("EMAIL") or "") |
|
155 | os.environ.get("EMAIL") or "") | |
|
156 | ||||
|
157 | def caching(web, req): | |||
|
158 | tag = str(web.mtime) | |||
|
159 | if req.env.get('HTTP_IF_NONE_MATCH') == tag: | |||
|
160 | raise ErrorResponse(HTTP_NOT_MODIFIED) | |||
|
161 | req.headers.append(('ETag', tag)) |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | from mercurial import ui, hg, hook, error, encoding, templater |
|
10 | from mercurial import ui, hg, hook, error, encoding, templater | |
11 | from common import get_mtime, ErrorResponse, permhooks |
|
11 | from common import get_mtime, ErrorResponse, permhooks, caching | |
12 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
12 | from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR | |
13 | from request import wsgirequest |
|
13 | from request import wsgirequest | |
14 | import webcommands, protocol, webutil |
|
14 | import webcommands, protocol, webutil | |
@@ -178,6 +178,7 b' class hgweb(object):' | |||||
178 | req.form['cmd'] = [tmpl.cache['default']] |
|
178 | req.form['cmd'] = [tmpl.cache['default']] | |
179 | cmd = req.form['cmd'][0] |
|
179 | cmd = req.form['cmd'][0] | |
180 |
|
180 | |||
|
181 | caching(self, req) # sets ETag header or raises NOT_MODIFIED | |||
181 | if cmd not in webcommands.__all__: |
|
182 | if cmd not in webcommands.__all__: | |
182 | msg = 'no such method: %s' % cmd |
|
183 | msg = 'no such method: %s' % cmd | |
183 | raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
|
184 | raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
@@ -23,7 +23,7 b' def startrsp(status, headers):' | |||||
23 | print '---- STATUS' |
|
23 | print '---- STATUS' | |
24 | print status |
|
24 | print status | |
25 | print '---- HEADERS' |
|
25 | print '---- HEADERS' | |
26 | print headers |
|
26 | print [i for i in headers if i[0] != 'ETag'] | |
27 | print '---- DATA' |
|
27 | print '---- DATA' | |
28 | return output.write |
|
28 | return output.write | |
29 |
|
29 |
@@ -23,7 +23,7 b' def startrsp(status, headers):' | |||||
23 | print '---- STATUS' |
|
23 | print '---- STATUS' | |
24 | print status |
|
24 | print status | |
25 | print '---- HEADERS' |
|
25 | print '---- HEADERS' | |
26 | print headers |
|
26 | print [i for i in headers if i[0] != 'ETag'] | |
27 | print '---- DATA' |
|
27 | print '---- DATA' | |
28 | return output.write |
|
28 | return output.write | |
29 |
|
29 |
@@ -40,7 +40,7 b' def startrsp(status, headers):' | |||||
40 | print '---- STATUS' |
|
40 | print '---- STATUS' | |
41 | print status |
|
41 | print status | |
42 | print '---- HEADERS' |
|
42 | print '---- HEADERS' | |
43 | print headers |
|
43 | print [i for i in headers if i[0] != 'ETag'] | |
44 | print '---- DATA' |
|
44 | print '---- DATA' | |
45 | return output.write |
|
45 | return output.write | |
46 |
|
46 |
General Comments 0
You need to be logged in to leave comments.
Login now