comparison mercurial/keepalive.py @ 8233:655c435efe92

keepalive: fix 4f13ed6ee544, reintroduce unredirected_hdrs The previous fix dropped unredirected_hdrs which contain authentication headers. Removing them break POST request requiring authentication (like unbundle calls to bitbucket.org).
author Patrick Mezard <pmezard@gmail.com>
date Mon, 27 Apr 2009 22:15:36 +0200
parents 4f13ed6ee544
children 908c5906091b
comparison
equal deleted inserted replaced
8232:823f25b25dea 8233:655c435efe92
305 if DEBUG: DEBUG.info("re-using connection to %s (%d)", host, id(h)) 305 if DEBUG: DEBUG.info("re-using connection to %s (%d)", host, id(h))
306 306
307 return r 307 return r
308 308
309 def _start_transaction(self, h, req): 309 def _start_transaction(self, h, req):
310 # What follows mostly reimplements HTTPConnection.request()
311 # except it adds self.parent.addheaders in the mix.
312 headers = req.headers.copy()
313 if sys.version_info >= (2, 4):
314 headers.update(req.unredirected_hdrs)
315 headers.update(self.parent.addheaders)
316 headers = dict((n.lower(), v) for n,v in headers.items())
317 skipheaders = {}
318 for n in ('host', 'accept-encoding'):
319 if n in headers:
320 skipheaders['skip_' + n.replace('-', '_')] = 1
310 try: 321 try:
311 if req.has_data(): 322 if req.has_data():
312 data = req.get_data() 323 data = req.get_data()
313 h.putrequest('POST', req.get_selector()) 324 h.putrequest('POST', req.get_selector(), **skipheaders)
314 if 'Content-type' not in req.headers: 325 if 'content-type' not in headers:
315 h.putheader('Content-type', 326 h.putheader('Content-type',
316 'application/x-www-form-urlencoded') 327 'application/x-www-form-urlencoded')
317 if 'Content-length' not in req.headers: 328 if 'content-length' not in headers:
318 h.putheader('Content-length', '%d' % len(data)) 329 h.putheader('Content-length', '%d' % len(data))
319 else: 330 else:
320 h.putrequest('GET', req.get_selector()) 331 h.putrequest('GET', req.get_selector(), **skipheaders)
321 except (socket.error), err: 332 except (socket.error), err:
322 raise urllib2.URLError(err) 333 raise urllib2.URLError(err)
323 334 for k, v in headers.items():
324 for args in self.parent.addheaders:
325 h.putheader(*args)
326 for k, v in req.headers.items():
327 h.putheader(k, v) 335 h.putheader(k, v)
328 h.endheaders() 336 h.endheaders()
329 if req.has_data(): 337 if req.has_data():
330 h.send(data) 338 h.send(data)
331 339