def handleResponse(self, response): if self.quietLoss: return if self.failed: self.factory.noPage( failure.Failure( error.Error( self.status, self.message, response))) elif self.length != None and self.length != 0: self.factory.noPage(failure.Failure( client.PartialDownloadError(self.status, self.message, response))) else: if self.decode: s = StringIO() s.write(response) s.seek(-1) g = GzipFile(fileobj=s, mode='rb') try: response = g.read() except IOError: self.factory.noPage(failure.Failure( client.PartialDownloadError(self.status, self.message, response))) self.transport.loseConnection() return g.close() self.factory.page(response) # server might be stupid and not close connection. self.transport.loseConnection()
def handleResponse(self, response): if self.quietLoss: return if self.failed: self.factory.noPage( failure.Failure( error.Error( self.status, self.message, response))) elif self.factory.method != 'HEAD' and self.length != None and self.length != 0: self.factory.noPage(failure.Failure( client.PartialDownloadError(self.status, self.message, response))) else: if(self.headers.has_key('transfer-encoding') and self.headers['transfer-encoding'][0].lower() == 'chunked'): self.factory.page(de_chunk_payload(response)) else: self.factory.page(response) # server might be stupid and not close connection. admittedly # the fact we do only one request per connection is also # stupid... self.quietLoss = 1 self.transport.loseConnection()