Skip to content
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

Keep auth header during http->https redirect #5848

Merged
merged 9 commits into from
Jul 22, 2021

Conversation

greshilov
Copy link
Contributor

@greshilov greshilov commented Jul 1, 2021

What do these changes do?

http->https redirect is a common thing today. It's safe to keep Authorization header in that situation if the host remains the same.
I'll create a separate PR for the 3.8 branch without this feature, but with the test and doc update (to emphasize, that this feature is 4+ only).

Are there changes in behavior for the user?

Authorization header wouldn't be dropped during the http->https redirect if the host remains the same.

Related issue number

Resolves #5783

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jul 1, 2021
@codecov
Copy link

codecov bot commented Jul 1, 2021

Codecov Report

Merging #5848 (3af8f33) into master (3d73221) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5848   +/-   ##
=======================================
  Coverage   96.75%   96.75%           
=======================================
  Files          44       44           
  Lines        9851     9852    +1     
  Branches     1591     1591           
=======================================
+ Hits         9531     9532    +1     
  Misses        182      182           
  Partials      138      138           
Flag Coverage Δ
unit 96.65% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/client.py 94.00% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d73221...3af8f33. Read the comment docs.

Comment on lines 2389 to 2390
server_a = await create_server(yarl_a, srv1)
server_b = await create_server(yarl_b, srv2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem as above with a/b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

docs/client_advanced.rst Outdated Show resolved Hide resolved
aiohttp/client.py Outdated Show resolved Hide resolved
CHANGES/5783.feature Outdated Show resolved Hide resolved
.. note::
``Authorization`` header will be removed if you get redirected
to a different host or protocol, except the case when ``HTTP -> HTTPS``
redirect is performed on the same host.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz keep that versionchanged with a very small note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added versionchanged with text from CHANGES/5783.feature

ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
cert.configure_cert(ssl_ctx)
kwargs["ssl"] = ssl_ctx
return await aiohttp_server(app, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could drop await here and async at the top and the interface would remain the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks!

async def srv1(request):
assert request.host == "host1.com"
assert request.host == yarl_a.host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same problem with naming: yarl_a? b? c? it needs to have words referring to things it represents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed all redirect related variables using from,to convention!

url_to: str,
is_drop_header_expected: bool,
) -> None:
yarl_a = URL(url_from)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use a lib name to describe a URL? why not just a URL? You could even just reuse the same variable name, right? Maybe you could even just wrap params in the decorator with yarl.URL() and keep it out of the test body to reduce the cognitive complexity of this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right.

@greshilov
Copy link
Contributor Author

@webknjaz PTAL
It feels like PR is almost there.

@webknjaz webknjaz merged commit 98d97cc into aio-libs:master Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ClientSession behavior] Authorization header dropped during HTTP redirect
2 participants