summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-02-04 16:11:28 -0200
committerdrebs <drebs@leap.se>2017-04-04 18:27:35 +0200
commitd1af3fcbedfd2c709c125236561646e71baec403 (patch)
treeeb02a565a0bb35e50c9132f11bf1a097c298b416 /client
parent47f95c81351a998150986f3551908167d0798d75 (diff)
[feature] add a treq-based http client to soledad client
Diffstat (limited to 'client')
-rw-r--r--client/src/leap/soledad/client/_http.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/_http.py b/client/src/leap/soledad/client/_http.py
index b5975772..20e61685 100644
--- a/client/src/leap/soledad/client/_http.py
+++ b/client/src/leap/soledad/client/_http.py
@@ -24,11 +24,47 @@ from twisted.web.iweb import IAgent
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
+from treq.client import HTTPClient as _HTTPClient
+
from zope.interface import implementer
from leap.common.certs import get_compatible_ssl_context_factory
+__all__ = ['HTTPClient', 'PinnedTokenAgent']
+
+
+class HTTPClient(object):
+
+ def __init__(self, uuid, token, cert_file):
+ self._agent = PinnedTokenAgent(uuid, token, cert_file)
+ self._client = _HTTPClient(self._agent)
+
+ def set_token(self, token):
+ self._agent.set_token(token)
+
+ def head(self, url, **kwargs):
+ return self._client.head(url, **kwargs)
+
+ def get(self, url, headers=None, **kwargs):
+ return self._client.get(url, headers=headers, **kwargs)
+
+ def post(self, url, data=None, **kwargs):
+ return self._client.post(url, data=data, **kwargs)
+
+ def put(self, url, data=None, **kwargs):
+ return self._client.put(url, data=data, **kwargs)
+
+ def patch(self, url, data=None, **kwargs):
+ return self._client.patch(url, data=data, **kwargs)
+
+ def delete(self, url, **kwargs):
+ return self._client.delete(url, **kwargs)
+
+ def request(self, method, url, **kwargs):
+ return self._client.request(method, url, **kwargs)
+
+
@implementer(IAgent)
class PinnedTokenAgent(Agent):