Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/server.py @ 39955:8c7ecd32ccce
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
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 01 Oct 2018 23:12:42 -0700 |
parents | d1e0b905c59d |
children | 197f092b2cd9 348352658e4b |
comparison
equal
deleted
inserted
replaced
39954:a3a9b93bff80 | 39955:8c7ecd32ccce |
---|---|
203 self.send_response(*saved_status) | 203 self.send_response(*saved_status) |
204 self.length = None | 204 self.length = None |
205 self._chunked = False | 205 self._chunked = False |
206 for h in self.saved_headers: | 206 for h in self.saved_headers: |
207 self.send_header(*h) | 207 self.send_header(*h) |
208 if h[0].lower() == 'content-length': | 208 if h[0].lower() == r'content-length': |
209 self.length = int(h[1]) | 209 self.length = int(h[1]) |
210 if (self.length is None and | 210 if (self.length is None and |
211 saved_status[0] != common.HTTP_NOT_MODIFIED): | 211 saved_status[0] != common.HTTP_NOT_MODIFIED): |
212 self._chunked = (not self.close_connection and | 212 self._chunked = (not self.close_connection and |
213 self.request_version == "HTTP/1.1") | 213 self.request_version == r'HTTP/1.1') |
214 if self._chunked: | 214 if self._chunked: |
215 self.send_header(r'Transfer-Encoding', r'chunked') | 215 self.send_header(r'Transfer-Encoding', r'chunked') |
216 else: | 216 else: |
217 self.send_header(r'Connection', r'close') | 217 self.send_header(r'Connection', r'close') |
218 self.end_headers() | 218 self.end_headers() |
221 def _start_response(self, http_status, headers, exc_info=None): | 221 def _start_response(self, http_status, headers, exc_info=None): |
222 assert isinstance(http_status, str) | 222 assert isinstance(http_status, str) |
223 code, msg = http_status.split(None, 1) | 223 code, msg = http_status.split(None, 1) |
224 code = int(code) | 224 code = int(code) |
225 self.saved_status = http_status | 225 self.saved_status = http_status |
226 bad_headers = ('connection', 'transfer-encoding') | 226 bad_headers = (r'connection', r'transfer-encoding') |
227 self.saved_headers = [h for h in headers | 227 self.saved_headers = [h for h in headers |
228 if h[0].lower() not in bad_headers] | 228 if h[0].lower() not in bad_headers] |
229 return self._write | 229 return self._write |
230 | 230 |
231 def _write(self, data): | 231 def _write(self, data): |