[tor-commits] [ooni-probe/master] Add logPrefixes to txagentwithsocks
art at torproject.org
art at torproject.org
Mon Nov 26 12:40:55 UTC 2012
commit 4b1c96d43520b2fd6df72e7e4845c879677d4c63
Author: Arturo Filastò <art at fuffa.org>
Date: Mon Nov 26 13:15:02 2012 +0100
Add logPrefixes to txagentwithsocks
* Improve http test template
---
ooni/templates/httpt.py | 9 +++++----
ooni/utils/txagentwithsocks.py | 18 ++++++++++++++++--
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index 2a368a0..480d011 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -66,6 +66,7 @@ class HTTPTest(NetTestCase):
self.control_agent = Agent(reactor, sockshost="127.0.0.1",
socksport=config.advanced.tor_socksport)
+ self.report['socksproxy'] = None
sockshost, socksport = (None, None)
if self.localOptions['socksproxy']:
try:
@@ -100,7 +101,7 @@ class HTTPTest(NetTestCase):
def processInputs(self):
pass
- def addToReport(self, request, response=None):
+ def addToReport(self, request, response=None, response_body=None):
"""
Adds to the report the specified request and response.
@@ -125,12 +126,12 @@ class HTTPTest(NetTestCase):
'headers': list(response.headers.getAllRawHeaders()),
'body': response_body,
'code': response.code
- }
+ }
self.report['requests'].append(request_response)
def _processResponseBody(self, response_body, request, response, body_processor):
log.debug("Processing response body")
- self.addToReport(request, response)
+ self.addToReport(request, response, response_body)
if body_processor:
body_processor(response_body)
else:
@@ -200,10 +201,10 @@ class HTTPTest(NetTestCase):
"""
if not response:
log.err("Got no response for request %s" % request)
+ self.addToReport(request, response)
return
else:
log.debug("Got response %s" % response)
- return
if str(response.code).startswith('3'):
self.processRedirect(response.headers.getRawHeaders('Location')[0])
diff --git a/ooni/utils/txagentwithsocks.py b/ooni/utils/txagentwithsocks.py
index 49e5a3c..ffaa733 100644
--- a/ooni/utils/txagentwithsocks.py
+++ b/ooni/utils/txagentwithsocks.py
@@ -32,6 +32,9 @@ class SOCKSv5ClientProtocol(_WrappingProtocol):
self._port = port
self.ready = False
+ def logPrefix(self):
+ return 'SOCKSv5ClientProtocol'
+
def socks_state_0(self, data):
# error state
self._connectedDeferred.errback(SOCKSError(0x00))
@@ -90,6 +93,9 @@ class SOCKSv5ClientFactory(_WrappingFactory):
_WrappingFactory.__init__(self, wrappedFactory)
self._host, self._port = host, port
+ def logPrefix(self):
+ return 'SOCKSv5ClientFactory'
+
def buildProtocol(self, addr):
try:
proto = self._wrappedFactory.buildProtocol(addr)
@@ -113,6 +119,9 @@ class SOCKS5ClientEndpoint(object):
self._timeout = timeout
self._bindAddress = bindAddress
+ def logPrefix(self):
+ return 'SOCKSv5ClientEndpoint'
+
def connect(self, protocolFactory):
try:
wf = SOCKSv5ClientFactory(protocolFactory, self._host, self._port)
@@ -123,6 +132,7 @@ class SOCKS5ClientEndpoint(object):
except:
return defer.fail()
+
class TrueHeaders(http_headers.Headers):
def __init__(self, rawHeaders=None):
self._rawHeaders = dict()
@@ -183,6 +193,9 @@ class TrueHeaders(http_headers.Headers):
return default
class HTTPClientParser(_newclient.HTTPClientParser):
+ def logPrefix(self):
+ return 'HTTPClientParser'
+
def connectionMade(self):
self.headers = TrueHeaders()
self.connHeaders = TrueHeaders()
@@ -196,7 +209,6 @@ class HTTPClientParser(_newclient.HTTPClientParser):
headers = self.headers
headers.addRawHeader(name, value)
-
class HTTP11ClientProtocol(_newclient.HTTP11ClientProtocol):
def request(self, request):
if self._state != 'QUIESCENT':
@@ -261,6 +273,9 @@ class Agent(client.Agent):
self._sockshost = sockshost
self._socksport = socksport
+ def logPrefix(self):
+ return 'SOCKSAgent'
+
def request(self, method, uri, headers=None, bodyProducer=None):
if (uri.startswith('shttp') or uri.startswith('httpo')) and not HTTPConnectionPool:
log.err("Requests over SOCKS are supported only with versions of Twisted >= 12.1.0")
@@ -297,7 +312,6 @@ class Agent(client.Agent):
parsedURI.host, parsedURI.port))
d = self._pool.getConnection(key, endpoint)
- print headers._rawHeaders
def cbConnected(proto):
return proto.request(
Request(method, requestPath, headers, bodyProducer,
More information about the tor-commits
mailing list