Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.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 | 7066617187c1 |
children | 98baf8dea553 |
comparison
equal
deleted
inserted
replaced
36874:8ddb5c354906 | 36875:7ad6a275316f |
---|---|
212 """ | 212 """ |
213 return (config("web", "contact") or | 213 return (config("web", "contact") or |
214 config("ui", "username") or | 214 config("ui", "username") or |
215 encoding.environ.get("EMAIL") or "") | 215 encoding.environ.get("EMAIL") or "") |
216 | 216 |
217 def caching(web, req): | |
218 tag = r'W/"%d"' % web.mtime | |
219 if req.env.get('HTTP_IF_NONE_MATCH') == tag: | |
220 raise ErrorResponse(HTTP_NOT_MODIFIED) | |
221 req.headers.append(('ETag', tag)) | |
222 | |
223 def cspvalues(ui): | 217 def cspvalues(ui): |
224 """Obtain the Content-Security-Policy header and nonce value. | 218 """Obtain the Content-Security-Policy header and nonce value. |
225 | 219 |
226 Returns a 2-tuple of the CSP header value and the nonce value. | 220 Returns a 2-tuple of the CSP header value and the nonce value. |
227 | 221 |