Repository navigation
Commit 44bbdb8
authored
Resolve same-scheme redirects without an authority against the URL (aio-libs#13855)
<!-- Thank you for your contribution! -->
## What do these changes do?
A redirect `Location` that has the scheme of the current URL but no
`//`, such as `http:/path` or `http:path`, is now joined with the
current URL, as browsers and the WHATWG URL Standard resolve it.
Previously only a `Location` without a scheme was joined, so
`http:/example.com` was taken as an absolute URL without a host and
failed with `InvalidUrlRedirectClientError`.
This is needed for aio-libs/yarl#1937, where yarl reads
`http:example.com/` as `http://example.com/` in its default WHATWG mode.
Without the join, aiohttp would follow `Location: http:/example.com` to
the host `example.com`, while a browser stays on the current host.
`Location: http:///example.com` is left as it was (still rejected):
browsers read it as the host `example.com`, which `URL.join()` does not
do. The check for `//` normalizes the Location as URL parsers do
(surrounding C0 controls and spaces stripped, tabs and newlines dropped)
and reads a backslash like a slash, as browsers do for http and https.
`http:/example.com` is removed from the invalid URL test data: a request
to it is invalid with the released yarl but goes to `example.com` with
yarl#1937. As a redirect it now resolves on both.
## Are there changes in behavior for the user?
Yes. `Location: http:/path`, `http:path` and `http:/` now redirect to
that path on the current host instead of raising
`InvalidUrlRedirectClientError`.
## Is it a substantial burden for the maintainers to support this?
No, it is one condition in the redirect handling.
## Related issue number
Needed by aio-libs/yarl#1937, whose "Aiohttp tests" job fails on
`http:/example.com` without it.
## Checklist
- [x] I think the code is well written
- [x] Unit tests for the changes exist
- [ ] Documentation reflects the changes: N/A, no documented behavior
changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`: N/A, already listed
- [x] Add a new news fragment into the `CHANGES/` folder
Drafted with Claude Code (Claude Opus 5.5); reviewed by @asvetlov.
<details>
<summary>Agent run details (optional, for reviewers)</summary>
Tests: `AIOHTTP_NO_EXTENSIONS=1 pytest tests -n auto`, 4796 passed, 60
skipped, 14 xfailed, both with yarl master (f761c37) and with the
yarl#1937 branch.
Lint: black, isort, codespell passed; flake8 (E, F, W) passed when run
directly, because the local pre-commit flake8 hook fails to load
`flake8-requirements` (`pkg_resources` missing); mypy on
`aiohttp/client.py` reports the same unrelated errors as on master.
</details>1 parent 31b6ebe commit 44bbdb8
4 files changed
Lines changed: 88 additions & 4 deletions
File tree
- CHANGES
- aiohttp
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
171 | 187 | | |
172 | 188 | | |
173 | 189 | | |
| |||
834 | 850 | | |
835 | 851 | | |
836 | 852 | | |
837 | | - | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
838 | 858 | | |
839 | 859 | | |
840 | 860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
1009 | 1041 | | |
1010 | 1042 | | |
1011 | 1043 | | |
| |||
3213 | 3245 | | |
3214 | 3246 | | |
3215 | 3247 | | |
3216 | | - | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
3217 | 3254 | | |
3218 | 3255 | | |
3219 | 3256 | | |
| |||
3259 | 3296 | | |
3260 | 3297 | | |
3261 | 3298 | | |
3262 | | - | |
| 3299 | + | |
3263 | 3300 | | |
3264 | 3301 | | |
3265 | 3302 | | |
| |||
3294 | 3331 | | |
3295 | 3332 | | |
3296 | 3333 | | |
3297 | | - | |
| 3334 | + | |
3298 | 3335 | | |
3299 | 3336 | | |
3300 | 3337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1729 | 1729 | | |
1730 | 1730 | | |
1731 | 1731 | | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
0 commit comments