Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 36875:7ad6a275316f
hgweb: inline caching() and port to modern mechanisms
We only had one consumer of this simple function. While it could be
a generic function, let's not over abstract the code.
As part of inlining, we port it off wsgirequest, fix some Python 3
issues, and set a response header on our new response object so it
is ready once we start using it to send responses.
Differential Revision: https://phab.mercurial-scm.org/D2785
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 10 Mar 2018 14:19:27 -0800 |
parents | 8ddb5c354906 |
children | 1f42d621f090 |
comparison
equal
deleted
inserted
replaced
36874:8ddb5c354906 | 36875:7ad6a275316f |
---|---|
16 HTTP_BAD_REQUEST, | 16 HTTP_BAD_REQUEST, |
17 HTTP_NOT_FOUND, | 17 HTTP_NOT_FOUND, |
18 HTTP_NOT_MODIFIED, | 18 HTTP_NOT_MODIFIED, |
19 HTTP_OK, | 19 HTTP_OK, |
20 HTTP_SERVER_ERROR, | 20 HTTP_SERVER_ERROR, |
21 caching, | |
22 cspvalues, | 21 cspvalues, |
23 permhooks, | 22 permhooks, |
24 ) | 23 ) |
25 | 24 |
26 from .. import ( | 25 from .. import ( |
386 cmd = req.qsparams['cmd'] | 385 cmd = req.qsparams['cmd'] |
387 | 386 |
388 # Don't enable caching if using a CSP nonce because then it wouldn't | 387 # Don't enable caching if using a CSP nonce because then it wouldn't |
389 # be a nonce. | 388 # be a nonce. |
390 if rctx.configbool('web', 'cache') and not rctx.nonce: | 389 if rctx.configbool('web', 'cache') and not rctx.nonce: |
391 caching(self, wsgireq) # sets ETag header or raises NOT_MODIFIED | 390 tag = 'W/"%d"' % self.mtime |
391 if req.headers.get('If-None-Match') == tag: | |
392 raise ErrorResponse(HTTP_NOT_MODIFIED) | |
393 | |
394 wsgireq.headers.append((r'ETag', pycompat.sysstr(tag))) | |
395 res.headers['ETag'] = tag | |
396 | |
392 if cmd not in webcommands.__all__: | 397 if cmd not in webcommands.__all__: |
393 msg = 'no such method: %s' % cmd | 398 msg = 'no such method: %s' % cmd |
394 raise ErrorResponse(HTTP_BAD_REQUEST, msg) | 399 raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
395 elif cmd == 'file' and req.qsparams.get('style') == 'raw': | 400 elif cmd == 'file' and req.qsparams.get('style') == 'raw': |
396 rctx.ctype = ctype | 401 rctx.ctype = ctype |