Show More
@@ -495,6 +495,10 b' class HTTPConnection(object):' | |||||
495 | else: |
|
495 | else: | |
496 | raise BadRequestData('body has no __len__() nor read()') |
|
496 | raise BadRequestData('body has no __len__() nor read()') | |
497 |
|
497 | |||
|
498 | # If we're reusing the underlying socket, there are some | |||
|
499 | # conditions where we'll want to retry, so make a note of the | |||
|
500 | # state of self.sock | |||
|
501 | fresh_socket = self.sock is None | |||
498 | self._connect() |
|
502 | self._connect() | |
499 | outgoing_headers = self._buildheaders( |
|
503 | outgoing_headers = self._buildheaders( | |
500 | method, path, hdrs, self.http_version) |
|
504 | method, path, hdrs, self.http_version) | |
@@ -640,6 +644,26 b' class HTTPConnection(object):' | |||||
640 | # the whole request |
|
644 | # the whole request | |
641 | if response is None: |
|
645 | if response is None: | |
642 | response = self.response_class(self.sock, self.timeout, method) |
|
646 | response = self.response_class(self.sock, self.timeout, method) | |
|
647 | if not fresh_socket: | |||
|
648 | if not response._select(): | |||
|
649 | # This means the response failed to get any response | |||
|
650 | # data at all, and in all probability the socket was | |||
|
651 | # closed before the server even saw our request. Try | |||
|
652 | # the request again on a fresh socket. | |||
|
653 | logging.debug('response._select() failed during request().' | |||
|
654 | ' Assuming request needs to be retried.') | |||
|
655 | self.sock = None | |||
|
656 | # Call this method explicitly to re-try the | |||
|
657 | # request. We don't use self.request() because | |||
|
658 | # some tools (notably Mercurial) expect to be able | |||
|
659 | # to subclass and redefine request(), and they | |||
|
660 | # don't have the same argspec as we do. | |||
|
661 | # | |||
|
662 | # TODO restructure sending of requests to avoid | |||
|
663 | # this recursion | |||
|
664 | return HTTPConnection.request( | |||
|
665 | self, method, path, body=body, headers=headers, | |||
|
666 | expect_continue=expect_continue) | |||
643 | data_left = bool(outgoing_headers or body) |
|
667 | data_left = bool(outgoing_headers or body) | |
644 | if data_left: |
|
668 | if data_left: | |
645 | logger.info('stopped sending request early, ' |
|
669 | logger.info('stopped sending request early, ' |
General Comments 0
You need to be logged in to leave comments.
Login now