r47354 - apply patch from lukasa, refs #8318
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Fri, 6 May 2016 09:19:35 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Fri May 6 09:19:31 2016
New Revision: 47354
Added:
branches/abort-oldclient-8318/twisted/web/topfiles/8318.bugfix
Modified:
branches/abort-oldclient-8318/twisted/web/client.py
branches/abort-oldclient-8318/twisted/web/test/test_webclient.py
Log:
apply patch from lukasa, refs #8318
Modified: branches/abort-oldclient-8318/twisted/web/client.py
==============================================================================
--- branches/abort-oldclient-8318/twisted/web/client.py (original)
+++ branches/abort-oldclient-8318/twisted/web/client.py Fri May 6 09:19:31 2016
@@ -246,7 +246,7 @@
def timeout(self):
self.quietLoss = True
- self.transport.loseConnection()
+ self.transport.abortConnection()
self.factory.noPage(defer.TimeoutError("Getting %s took longer than %s seconds." % (self.factory.url, self.factory.timeout)))
Modified: branches/abort-oldclient-8318/twisted/web/test/test_webclient.py
==============================================================================
--- branches/abort-oldclient-8318/twisted/web/test/test_webclient.py (original)
+++ branches/abort-oldclient-8318/twisted/web/test/test_webclient.py Fri May 6 09:19:31 2016
@@ -90,6 +90,20 @@
return server.NOT_DONE_YET
+class ForeverTakingNoReadingResource(resource.Resource):
+ """
+ L{ForeverTakingNoReadingResource} is a resource that never finishes
+ responding and that removes itself from the read loop.
+ """
+ def __init__(self):
+ resource.Resource.__init__(self)
+
+ def render(self, request):
+ # Stop the producing.
+ request.transport.pauseProducing()
+ return server.NOT_DONE_YET
+
+
class CookieMirrorResource(resource.Resource):
def render(self, request):
l = []
@@ -291,6 +305,7 @@
r.putChild(b"infiniteRedirect", self.infiniteRedirectResource)
r.putChild(b"wait", ForeverTakingResource())
r.putChild(b"write-then-wait", ForeverTakingResource(write=True))
+ r.putChild(b"never-read", ForeverTakingNoReadingResource())
r.putChild(b"error", ErrorResource())
r.putChild(b"nolength", NoLengthResource())
r.putChild(b"host", HostHeaderResource())
@@ -725,6 +740,25 @@
self.assertFailure(second, defer.TimeoutError)])
+ def test_downloadTimeoutsWorkWithoutReading(self):
+ """
+ If the timeout indicated by the C{timeout} parameter to
+ L{client.HTTPDownloader.__init__} elapses without the complete response
+ being received, the L{defer.Deferred} returned by
+ L{client.downloadPage} fires with a L{Failure} wrapping a
+ L{defer.TimeoutError}, even if the remote peer isn't reading data from
+ the socket.
+ """
+ self.cleanupServerConnections = 1
+
+ # The timeout here needs to be slightly longer to give the resource a
+ # change to stop the reading.
+ d = client.downloadPage(
+ self.getURL("never-read"),
+ self.mktemp(), timeout=0.05)
+ return self.assertFailure(d, defer.TimeoutError)
+
+
def test_downloadHeaders(self):
"""
After L{client.HTTPDownloader.deferred} fires, the