comparison mercurial/httpclient/__init__.py @ 15218:c81dce8a7bb6

httpclient: update to 07d8c356f4d1 of py-nonblocking-http This addresses a defect when the server closes the socket before finishing a response (if it crashes, for example) first spotted in Issue2951.
author Augie Fackler <durin42@gmail.com>
date Mon, 10 Oct 2011 17:57:40 -0500
parents a75e0f4ba0ab
children 24dbef11f477
comparison
equal deleted inserted replaced
15217:42d0d4f63bf0 15218:c81dce8a7bb6
169 logger.info('timed out with timeout of %s', self._timeout) 169 logger.info('timed out with timeout of %s', self._timeout)
170 raise HTTPTimeoutException('timeout reading data') 170 raise HTTPTimeoutException('timeout reading data')
171 logger.info('cl: %r body: %r', self._content_len, self._body) 171 logger.info('cl: %r body: %r', self._content_len, self._body)
172 try: 172 try:
173 data = self.sock.recv(INCOMING_BUFFER_SIZE) 173 data = self.sock.recv(INCOMING_BUFFER_SIZE)
174 # If the socket was readable and no data was read, that
175 # means the socket was closed. If this isn't a
176 # _CLOSE_IS_END socket, then something is wrong if we're
177 # here (we shouldn't enter _select() if the response is
178 # complete), so abort.
179 if not data and self._content_len != _LEN_CLOSE_IS_END:
180 raise HTTPRemoteClosedError(
181 'server appears to have closed the socket mid-response')
174 except socket.sslerror, e: 182 except socket.sslerror, e:
175 if e.args[0] != socket.SSL_ERROR_WANT_READ: 183 if e.args[0] != socket.SSL_ERROR_WANT_READ:
176 raise 184 raise
177 logger.debug('SSL_WANT_READ in _select, should retry later') 185 logger.debug('SSL_WANT_READ in _select, should retry later')
178 return True 186 return True
691 699
692 700
693 class HTTPProxyConnectFailedException(httplib.HTTPException): 701 class HTTPProxyConnectFailedException(httplib.HTTPException):
694 """Connecting to the HTTP proxy failed.""" 702 """Connecting to the HTTP proxy failed."""
695 703
704
696 class HTTPStateError(httplib.HTTPException): 705 class HTTPStateError(httplib.HTTPException):
697 """Invalid internal state encountered.""" 706 """Invalid internal state encountered."""
707
708
709 class HTTPRemoteClosedError(httplib.HTTPException):
710 """The server closed the remote socket in the middle of a response."""
698 # no-check-code 711 # no-check-code