diff options
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r-- | client/src/leap/soledad/client/_http.py | 36 |
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): |