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
gh-73561: Omit interface scope from IPv6 when used as Host header #93324
gh-73561: Omit interface scope from IPv6 when used as Host header #93324
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
a10bb09
to
9290a01
Compare
9290a01
to
937cb17
Compare
@vstinner do you mind to have a look into the last changes? |
hi, is there any possibility, to get this small PR reviewed? I don't want to blame anybody direct, therefore i already followed the suggested way with "pinging" the connected issue and writing to the forum, but without success 🙁 |
Lib/http/client.py
Outdated
|
||
# remove interface scope from IPv6 address | ||
# when used as Host header | ||
if "%" in netloc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than checking netloc and modifying netloc_enc (which makes assumptions about the encoding - granted they're accurate so the logic works), how about doing this using the partition method for a single scan / split operation?
netloc_enc, percent, unused_iface = netloc_enc.partition(b"%")
if percent:
netloc_enc += b"]"
do similar with host_enc below.
There is technically a logic flaw in the current code, it's using netloc.find as an index into the encoded netloc_enc value. (same with host vs host_enc). the stripping should be done more directly from the same thing used for find. partition will do that.
As this is done in two places, it'd be nice to turn it into a private helper function, put that logic in a top level def _strip_ipv6_iface(enc_name: bytes) -> bytes:
function perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @gpshead
thank you for your review and your suggestion, which sounds very reasonable ... i've applied it now
1283ff9
to
43fc859
Compare
rebased to current |
…er (pythonGH-93324) Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`. --------- (cherry picked from commit ce1096f) Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
…er (pythonGH-93324) Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`. --------- (cherry picked from commit ce1096f) Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
GH-112272 is a backport of this pull request to the 3.12 branch. |
GH-112273 is a backport of this pull request to the 3.11 branch. |
Many thanks @gpshead for your support to get this ready and merged 🤝 |
thanks for the fix! |
…der (GH-93324) (#112272) gh-73561: Omit interface scope from IPv6 when used as Host header (GH-93324) Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`. --------- (cherry picked from commit ce1096f) [Google LLC] Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
…der (GH-93324) (#112273) gh-73561: Omit interface scope from IPv6 when used as Host header (GH-93324) Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`. --------- (cherry picked from commit ce1096f) [Google LLC] Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
…er (python#93324) Omit the `@interface_scope` from an IPv6 address when used as Host header by `http.client`. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google LLC]
This will omit the interface scope from IPv6 when used as Host header.
This should also be back ported to all maintenance releases.