Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 37827:11ee9bf24791 stable
hgweb: discard Content-Type header for 304 responses (issue5844)
A side-effect of 98baf8dea553 was that hgwebdir always sets a global
default for the Content-Type header. HTTP 304 responses don't allow
the Content-Type header. So a side-effect of this change was that
HTTP 304 responses served via hgwebdir resulted in a ProgrammingError
being raised.
This commit teaches our 304 response issuing code to drop the
Content-Type header.
Differential Revision: https://phab.mercurial-scm.org/D3435
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 30 Apr 2018 17:22:20 -0700 |
parents | b29f490eb904 |
children | 5b831053d9b6 |
comparison
equal
deleted
inserted
replaced
37826:d105bbb74658 | 37827:11ee9bf24791 |
---|---|
397 # be a nonce. | 397 # be a nonce. |
398 if rctx.configbool('web', 'cache') and not rctx.nonce: | 398 if rctx.configbool('web', 'cache') and not rctx.nonce: |
399 tag = 'W/"%d"' % self.mtime | 399 tag = 'W/"%d"' % self.mtime |
400 if req.headers.get('If-None-Match') == tag: | 400 if req.headers.get('If-None-Match') == tag: |
401 res.status = '304 Not Modified' | 401 res.status = '304 Not Modified' |
402 # Content-Type may be defined globally. It isn't valid on a | |
403 # 304, so discard it. | |
404 try: | |
405 del res.headers[b'Content-Type'] | |
406 except KeyError: | |
407 pass | |
402 # Response body not allowed on 304. | 408 # Response body not allowed on 304. |
403 res.setbodybytes('') | 409 res.setbodybytes('') |
404 return res.sendresponse() | 410 return res.sendresponse() |
405 | 411 |
406 res.headers['ETag'] = tag | 412 res.headers['ETag'] = tag |