Skip to content
Snippets Groups Projects
Commit 8c7ecd32 authored by Gregory Szorc's avatar Gregory Szorc
Browse files

py3: use system strings in HTTP server code

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.

Differential Revision: https://phab.mercurial-scm.org/D4833
parent a3a9b93b
Branches
Tags
No related merge requests found
......@@ -205,8 +205,8 @@
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
......@@ -209,8 +209,8 @@
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment