-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Update session default Authorization header #3299
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #1197 (Flask request headers), #1746 (Need possibility to modify client.Session default headers in constructed session), #1618 (allow HEAD requests to default routes), #1561 (Support proxy headers for CONNECT requests), and #3231 (Feature request: in the server, modifying the response headers after they have been sent should raise). |
After seeing #1746 (sorry I missed it aio-libs-bot++) it seems better if the new method is only capable of updating the 'Authorization' header. |
Sorry, modifying the defaults is a bad idea.
Please send headers on each request explicitly if you need a mutable state. It is pretty easy and straightforward. |
Thanks so much for the quick response @asvetlov. In this case what you described is the intended behavior, but I can make do with mutable headers. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
I would like to update headers for an entire session, but setting
ClientSession._default_headers
directly is discouraged. The use case for this is token auth, when the tokens expire in a relatively short time. It would be nice to be able to update all new requests for a single session with the new token.Expected behaviour
What I'd like to see is a new method:
ClientSession.update_default_headers
.Example use for the token auth use case:
Actual behaviour
It is technically possible to do this now, but requires the direct use of discouraged ClientSession.ATTRS. https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L76
Would you accept a PR?
I'm happy to open a PR. I think this would be as simple as:
Of course, this assumes that it is safe to update the default headers, and there may be a very good reason why it is discouraged to begin with.
The text was updated successfully, but these errors were encountered: