add utils.http.Session object, to preserve cookies across requests

This commit is contained in:
jesopo 2019-12-03 13:00:43 +00:00
parent a80c3396df
commit b889a9f841

View file

@ -205,6 +205,20 @@ def _request(request_obj: Request) -> Response:
return response
class Session(object):
def __init__(self):
self._cookies: typing.Dict[str, str] = {}
def __enter__(self):
pass
def __exit__(self):
self._cookies.clear()
def request(self, request: Request) -> Response:
request.cookies.update(self._cookies)
response = _request(request)
self._cookies.update(response.cookies)
return response
class RequestManyException(Exception):
pass
def request_many(requests: typing.List[Request]) -> typing.Dict[str, Response]: