Mercurial > public > mercurial-scm > hg
comparison mercurial/keepalive.py @ 8146:4f13ed6ee544
keepalive: attempt to fix issue1003
This is a reimport of the relevant piece of the upstream urlgrabber,
which appears to be more correct.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 23 Apr 2009 15:40:10 -0500 |
parents | 553aa0cbeab6 |
children | 655c435efe92 |
comparison
equal
deleted
inserted
replaced
8145:0c2ba48415c8 | 8146:4f13ed6ee544 |
---|---|
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 headers = req.headers.copy() | |
311 body = req.data | |
312 if sys.version_info >= (2, 4): | |
313 headers.update(req.unredirected_hdrs) | |
314 try: | 310 try: |
315 h.request(req.get_method(), req.get_selector(), body, headers) | 311 if req.has_data(): |
316 except socket.error, err: # XXX what error? | 312 data = req.get_data() |
313 h.putrequest('POST', req.get_selector()) | |
314 if 'Content-type' not in req.headers: | |
315 h.putheader('Content-type', | |
316 'application/x-www-form-urlencoded') | |
317 if 'Content-length' not in req.headers: | |
318 h.putheader('Content-length', '%d' % len(data)) | |
319 else: | |
320 h.putrequest('GET', req.get_selector()) | |
321 except (socket.error), err: | |
317 raise urllib2.URLError(err) | 322 raise urllib2.URLError(err) |
323 | |
324 for args in self.parent.addheaders: | |
325 h.putheader(*args) | |
326 for k, v in req.headers.items(): | |
327 h.putheader(k, v) | |
328 h.endheaders() | |
329 if req.has_data(): | |
330 h.send(data) | |
318 | 331 |
319 class HTTPHandler(KeepAliveHandler, urllib2.HTTPHandler): | 332 class HTTPHandler(KeepAliveHandler, urllib2.HTTPHandler): |
320 pass | 333 pass |
321 | 334 |
322 class HTTPResponse(httplib.HTTPResponse): | 335 class HTTPResponse(httplib.HTTPResponse): |