Mercurial > public > mercurial-scm > hg
comparison mercurial/keepalive.py @ 31999:aa836f56c3cc
keepalive: send HTTP request headers in a deterministic order
An upcoming patch will add low-level testing of the bytes being sent
over the wire. As part of developing that test, I discovered that the
order of headers in HTTP requests wasn't deterministic. This patch
makes the order deterministic to make things easier to test.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 13 Apr 2017 18:04:38 -0700 |
parents | 1beeb5185930 |
children | 2806c7bbcb5e |
comparison
equal
deleted
inserted
replaced
31998:83527d9f1f13 | 31999:aa836f56c3cc |
---|---|
296 | 296 |
297 return r | 297 return r |
298 | 298 |
299 def _start_transaction(self, h, req): | 299 def _start_transaction(self, h, req): |
300 # What follows mostly reimplements HTTPConnection.request() | 300 # What follows mostly reimplements HTTPConnection.request() |
301 # except it adds self.parent.addheaders in the mix. | 301 # except it adds self.parent.addheaders in the mix and sends headers |
302 headers = dict(self.parent.addheaders) | 302 # in a deterministic order (to make testing easier). |
303 headers.update(req.headers) | 303 headers = util.sortdict(self.parent.addheaders) |
304 headers.update(req.unredirected_hdrs) | 304 headers.update(sorted(req.headers.items())) |
305 headers = dict((n.lower(), v) for n, v in headers.items()) | 305 headers.update(sorted(req.unredirected_hdrs.items())) |
306 headers = util.sortdict((n.lower(), v) for n, v in headers.items()) | |
306 skipheaders = {} | 307 skipheaders = {} |
307 for n in ('host', 'accept-encoding'): | 308 for n in ('host', 'accept-encoding'): |
308 if n in headers: | 309 if n in headers: |
309 skipheaders['skip_' + n.replace('-', '_')] = 1 | 310 skipheaders['skip_' + n.replace('-', '_')] = 1 |
310 try: | 311 try: |