commit 47eb5dd08d0f0cc94bc2e8013cc38e8509b4d2a4 Author: Arturo Filastò art@fuffa.org Date: Thu Jan 30 17:51:12 2014 +0100
Move the creation of the Agent into the request
Allowing dynamic changing of the address class attribute. Raise exception when an invalid URL is provided. --- ooni/errors.py | 3 +++ ooni/oonibclient.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py index c167bbe..6896244 100644 --- a/ooni/errors.py +++ b/ooni/errors.py @@ -133,6 +133,9 @@ class UnableToStartTor(DirectorException): class InvalidOONIBCollectorAddress(Exception): pass
+class InvalidOONIBBouncerAddress(Exception): + pass + class AllReportersFailed(Exception): pass
diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py index af4328b..6eff112 100644 --- a/ooni/oonibclient.py +++ b/ooni/oonibclient.py @@ -44,17 +44,20 @@ class OONIBClient(object): retries = 3
def __init__(self, address): - if address.startswith('httpo://'): - self.address = address.replace('httpo://', 'http://') - self.agent = TrueHeadersSOCKS5Agent(reactor, + self.address = address + + + def _request(self, method, urn, genReceiver, bodyProducer=None): + if self.address.startswith('httpo://'): + self.address = self.address.replace('httpo://', 'http://') + agent = TrueHeadersSOCKS5Agent(reactor, proxyEndpoint=TCP4ClientEndpoint(reactor, '127.0.0.1', config.tor.socks_port))
- elif address.startswith('https://'): + elif self.address.startswith('https://'): log.err("HTTPS based bouncers are currently not supported.") + raise e.InvalidOONIBBouncerAddress
- - def _request(self, method, urn, genReceiver, bodyProducer=None): attempts = 0
finished = defer.Deferred() @@ -62,7 +65,7 @@ class OONIBClient(object): def perform_request(attempts): uri = self.address + urn headers = {} - d = self.agent.request(method, uri, bodyProducer=bodyProducer) + d = agent.request(method, uri, bodyProducer=bodyProducer)
@d.addCallback def callback(response):
tor-commits@lists.torproject.org