changeset 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 d105bbb74658
children 3e3acf5d6a07
files mercurial/hgweb/hgweb_mod.py tests/test-hgweb.t
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Mon Apr 30 17:08:56 2018 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Apr 30 17:22:20 2018 -0700
@@ -399,6 +399,12 @@
                 tag = 'W/"%d"' % self.mtime
                 if req.headers.get('If-None-Match') == tag:
                     res.status = '304 Not Modified'
+                    # Content-Type may be defined globally. It isn't valid on a
+                    # 304, so discard it.
+                    try:
+                        del res.headers[b'Content-Type']
+                    except KeyError:
+                        pass
                     # Response body not allowed on 304.
                     res.setbodybytes('')
                     return res.sendresponse()
--- a/tests/test-hgweb.t	Mon Apr 30 17:08:56 2018 -0700
+++ b/tests/test-hgweb.t	Mon Apr 30 17:22:20 2018 -0700
@@ -890,9 +890,7 @@
   200 Script output follows
   content-length: 2677
   content-type: text/css
-  500 Internal Server Error
-  transfer-encoding: chunked
-  [1]
+  304 Not Modified
 
   $ killdaemons.py