Patchwork D3435: hgweb: discard Content-Type header for 304 responses (issue5844)

login
register
mail settings
Submitter phabricator
Date May 1, 2018, 12:37 a.m.
Message ID <differential-rev-PHID-DREV-lu67bf2vqrcwikh23ztv-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/31248/
State Superseded
Headers show

Comments

phabricator - May 1, 2018, 12:37 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  A side-effect of https://phab.mercurial-scm.org/rHG98baf8dea553430c8093c244dbad8d79f4a23f88 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3435

AFFECTED FILES
  mercurial/hgweb/hgweb_mod.py
  tests/test-hgweb.t

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-hgweb.t b/tests/test-hgweb.t
--- a/tests/test-hgweb.t
+++ b/tests/test-hgweb.t
@@ -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
 
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -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()