[PATCH 02 of 11] keepalive: reorder header precedence

Gregory Szorc gregory.szorc at gmail.com
Sun Nov 20 17:23:39 EST 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1479604272 28800
#      Sat Nov 19 17:11:12 2016 -0800
# Node ID 5a19e48cea056be5ece370744f3ee40bfb5d7c7e
# Parent  55af8a76a48c276924a0ff9fbf4d2db1c2b31711
keepalive: reorder header precedence

There are 3 sources of headers used by this function:

* The default headers defined by the URL opener
* Headers that are copied on redirects
* Headers that aren't copied on redirects

Previously, we applied the default headers from the URL
opener last. This feels wrong to me as those headers are
the most low level and something built on top of the URL
opener may wish to override them. So, this commit changes
the order to apply them with the least precedence.

While I was here, I removed a Python version test that is
no longer necessary.

diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -332,10 +332,9 @@ class KeepAliveHandler(object):
     def _start_transaction(self, h, req):
         # What follows mostly reimplements HTTPConnection.request()
         # except it adds self.parent.addheaders in the mix.
-        headers = req.headers.copy()
-        if sys.version_info >= (2, 4):
-            headers.update(req.unredirected_hdrs)
-        headers.update(self.parent.addheaders)
+        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())
         skipheaders = {}
         for n in ('host', 'accept-encoding'):


More information about the Mercurial-devel mailing list