[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Fix bug that made HTTP based tests stall
commit 47d61ebfa76d87c4ca071bbfea728454b4be888b
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Wed Dec 26 16:28:56 2012 +0100
Fix bug that made HTTP based tests stall
The issue occurred when the server was configured to keep the connection alive.
Since I did not evaluate the content length field when passing it to the body
delivery Protocol connection lost would never occur and the test would stall
indefinitely.
---
ooni/templates/httpt.py | 8 ++++++--
ooni/utils/net.py | 8 +++++++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index 089aea5..a0e8eb1 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -220,11 +220,15 @@ class HTTPTest(NetTestCase):
else:
self.processResponseHeaders(response_headers_dict)
+ try:
+ content_length = response.headers.getRawHeaders('content-length')
+ except IndexError:
+ content_length = None
+
finished = defer.Deferred()
- response.deliverBody(BodyReceiver(finished))
+ response.deliverBody(BodyReceiver(finished, content_length))
finished.addCallback(self._processResponseBody, request,
response, body_processor)
-
return finished
def doRequest(self, url, method="GET",
diff --git a/ooni/utils/net.py b/ooni/utils/net.py
index 824d720..865977c 100644
--- a/ooni/utils/net.py
+++ b/ooni/utils/net.py
@@ -61,11 +61,17 @@ class StringProducer(object):
pass
class BodyReceiver(protocol.Protocol):
- def __init__(self, finished):
+ def __init__(self, finished, content_length=None):
self.finished = finished
self.data = ""
+ self.bytes_remaining = content_length
def dataReceived(self, bytes):
+ if self.bytes_remaining:
+ if self.bytes_remaining == 0:
+ self.connectionLost(None)
+ else:
+ self.bytes_remaining -= len(bytes)
self.data += bytes
def connectionLost(self, reason):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits