Mercurial > hg-stable
changeset 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 | 83527d9f1f13 |
children | 511a62669f1b |
files | mercurial/keepalive.py |
diffstat | 1 files changed, 6 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/keepalive.py Sat Apr 15 11:29:42 2017 +0200 +++ b/mercurial/keepalive.py Thu Apr 13 18:04:38 2017 -0700 @@ -298,11 +298,12 @@ def _start_transaction(self, h, req): # What follows mostly reimplements HTTPConnection.request() - # except it adds self.parent.addheaders in the mix. - headers = dict(self.parent.addheaders) - headers.update(req.headers) - headers.update(req.unredirected_hdrs) - headers = dict((n.lower(), v) for n, v in headers.items()) + # except it adds self.parent.addheaders in the mix and sends headers + # in a deterministic order (to make testing easier). + headers = util.sortdict(self.parent.addheaders) + headers.update(sorted(req.headers.items())) + headers.update(sorted(req.unredirected_hdrs.items())) + headers = util.sortdict((n.lower(), v) for n, v in headers.items()) skipheaders = {} for n in ('host', 'accept-encoding'): if n in headers: