def dataReceived(self, bytes): """ Receive some data and extend the timeout period of this request. :param bytes: A string of indeterminate length. :type bytes: str """ HTTP11ClientProtocol.dataReceived(self, bytes) if self._timeoutCall and self._timeoutCall.active(): self._timeoutCall.reset(self._timeout)
def __init__(self, quiescentCallback, timeout): """ Initialize the protocol. :param quiescentCallback: :type quiescentCallback: callable :param timeout: A timeout, in seconds, for requests made by this protocol. :type timeout: float """ HTTP11ClientProtocol.__init__(self, quiescentCallback) self._timeout = timeout self._timeoutCall = None
def request(self, request): """ Issue request over self.transport and return a Deferred which will fire with a Response instance or an error. :param request: The object defining the parameters of the request to issue. :type request: twisted.web._newclient.Request :return: A deferred which fires after the request has finished. :rtype: Deferred """ d = HTTP11ClientProtocol.request(self, request) if self._timeout: self._last_buffer_len = 0 timeoutCall = reactor.callLater( self._timeout, self._doTimeout, request) self._timeoutCall = timeoutCall return d
def request(self, request): """ Issue request over self.transport and return a Deferred which will fire with a Response instance or an error. :param request: The object defining the parameters of the request to issue. :type request: twisted.web._newclient.Request :return: A deferred which fires after the request has finished. :rtype: Deferred """ d = HTTP11ClientProtocol.request(self, request) if self._timeout: self._last_buffer_len = 0 timeoutCall = reactor.callLater(self._timeout, self._doTimeout, request) self._timeoutCall = timeoutCall return d
def request(self, request): if self.timeout: self.setTimeout(self.timeout) def _cb(result, self=self): # Reset timeouts self.setTimeout(None) return result def _eb(result, self=self): # Reset timeouts self.setTimeout(None) return result deferred = HTTP11ClientProtocol.request(self, request) deferred.addCallbacks(_cb, _eb) # Success return deferred
def connectionLost(self, reason): self._cancelTimeout() return HTTP11ClientProtocol.connectionLost(self, reason)
def _finishResponse(self, rest): """ Cancel the timeout when finished receiving the response. """ self._cancelTimeout() HTTP11ClientProtocol._finishResponse(self, rest)