comparison mercurial/keepalive.py @ 30463:bc0def54c17d

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 19 Nov 2016 17:11:12 -0800
parents e61d384e3be4
children 39d13b8c101d
comparison
equal deleted inserted replaced
30462:356406ac454f 30463:bc0def54c17d
330 return r 330 return r
331 331
332 def _start_transaction(self, h, req): 332 def _start_transaction(self, h, req):
333 # What follows mostly reimplements HTTPConnection.request() 333 # What follows mostly reimplements HTTPConnection.request()
334 # except it adds self.parent.addheaders in the mix. 334 # except it adds self.parent.addheaders in the mix.
335 headers = req.headers.copy() 335 headers = dict(self.parent.addheaders)
336 if sys.version_info >= (2, 4): 336 headers.update(req.headers)
337 headers.update(req.unredirected_hdrs) 337 headers.update(req.unredirected_hdrs)
338 headers.update(self.parent.addheaders)
339 headers = dict((n.lower(), v) for n, v in headers.items()) 338 headers = dict((n.lower(), v) for n, v in headers.items())
340 skipheaders = {} 339 skipheaders = {}
341 for n in ('host', 'accept-encoding'): 340 for n in ('host', 'accept-encoding'):
342 if n in headers: 341 if n in headers:
343 skipheaders['skip_' + n.replace('-', '_')] = 1 342 skipheaders['skip_' + n.replace('-', '_')] = 1