add utils.http.Session object, to preserve cookies across requests
This commit is contained in:
parent
a80c3396df
commit
b889a9f841
1 changed files with 14 additions and 0 deletions
|
@ -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]:
|
||||
|
|
Loading…
Reference in a new issue