D4833: py3: use system strings in HTTP server code

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Oct 2 06:17:51 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Previously the source transformer was converting some string literals
  to bytes and we were comparing a system native string to bytes
  and this was leading to sending the wrong HTTP response headers on
  Python 3.
  
  After this change, we now properly send Transfer-Encoding and
  Connection response headers on Python 3.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/hgweb/server.py

CHANGE DETAILS

diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -205,12 +205,12 @@
         self._chunked = False
         for h in self.saved_headers:
             self.send_header(*h)
-            if h[0].lower() == 'content-length':
+            if h[0].lower() == r'content-length':
                 self.length = int(h[1])
         if (self.length is None and
             saved_status[0] != common.HTTP_NOT_MODIFIED):
             self._chunked = (not self.close_connection and
-                             self.request_version == "HTTP/1.1")
+                             self.request_version == r'HTTP/1.1')
             if self._chunked:
                 self.send_header(r'Transfer-Encoding', r'chunked')
             else:
@@ -223,7 +223,7 @@
         code, msg = http_status.split(None, 1)
         code = int(code)
         self.saved_status = http_status
-        bad_headers = ('connection', 'transfer-encoding')
+        bad_headers = (r'connection', r'transfer-encoding')
         self.saved_headers = [h for h in headers
                               if h[0].lower() not in bad_headers]
         return self._write



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


More information about the Mercurial-devel mailing list