Patchwork [02,of,11] keepalive: reorder header precedence

mail settings
Submitter Gregory Szorc
Date Nov. 20, 2016, 10:23 p.m.
Message ID <5a19e48cea056be5ece3.1479680619@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17653/
State Accepted
Headers show


Gregory Szorc - Nov. 20, 2016, 10:23 p.m.
# HG changeset patch
# User Gregory Szorc <>
# 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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -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'):