diff options
| author | 2019-12-03 13:00:43 +0000 | |
|---|---|---|
| committer | 2019-12-03 13:00:43 +0000 | |
| commit | b889a9f8410e16af15cf7f3b4502c4784f21b12e (patch) | |
| tree | 11d886807997116ff1505e002245300043747b3e | |
| parent | show useful error message when failing to parse birthday setting (diff) | |
| signature | ||
add utils.http.Session object, to preserve cookies across requests
| -rw-r--r-- | src/utils/http.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/http.py b/src/utils/http.py index 83d6523b..eda5b947 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -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]: |
