Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The requests module internally works with Session objects. These can be customised in behaviour e.g. using retry adapters. This is extremely useful for error handling because the user application doesn't even get to see and need to handle errors until a configurable number of retries with optional backoff has been done. Unfortunately, the module-level API of the requests module does not allow to supply such a customised Session object. Instead it creates a new Session for each request and needs to use it as a context handler to make sure it leaks no sockets - see https://github.com/psf/requests/blob/143150233162d609330941ec2aacde5ed4caa510/requests/api.py#L57 for details. The module-level API is a very thin shim which directly hands all requests to this per-request Session object. This change switches the Cortex API layer to allow usage of a Session object for requests and adds a parameter so users can provide their own customised Session object. To keep default behaviour unchanged, a fresh internal session object is created for each request. This is done so the session does indeed not accumulate state over time. For example this prevents learning of cookies from responses which has been observed to confuse Cortex on subsequent requests. In the case of a user-supplied session it is the responsibility of the user to configure it in such a way that it serves their purpose and does not show behaviour that confuses Cortex. Signed-off-by: Michael Weiser <[email protected]>
- Loading branch information