feat: add -L flag for HTTP redirect following - #2
Merged
Merged
Conversation
- Add --follow-redirects / -L flag to follow 3xx responses automatically - 301/302/303: method downgraded to GET, body dropped - 307/308: method and body preserved - Relative and absolute-path Location values resolved via urljoin - Max 10 redirect hops; non-https redirects rejected - Binary-safe output via sys.stdout.buffer.write Tests: - tests/test_follow_redirects.py: 13 tests covering all redirect cases - tests/test_send_request.py: 29 tests covering general send_request/main behaviour CI: - .github/workflows/ci.yml: flake8 lint + tests on Python 3.9/3.11/3.13 - .flake8: config with per-file ignores for pre-existing style in src/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
--follow-redirects/-Lflag to automatically follow HTTP 3xx redirects, matchingcurl -Lbehaviour.Changes
src/h3/__init__.pyMAX_REDIRECTS = 10constanturljoinimport for relative URL resolution-L/--follow-redirectsargument toparse_args()send_request()into a redirect loop:Locationvalues resolved viaurljoinhttps://redirect targets rejected with an errorMAX_REDIRECTShopsHttp3ClientError,ProxyBadStatus,create_quic_configuration,send_requestTests
tests/test_follow_redirects.py— 13 tests: no-redirect default, single 301/302/307 follow, relative/absolute location resolution, POST→GET method downgrade, redirect loop guardtests/test_send_request.py— 29 tests: generalsend_requestbehaviour,main()arg-parsing, error paths, helper validation functionsCI
.github/workflows/ci.yml— flake8 lint + both test suites on Python 3.9 / 3.11 / 3.13.flake8— per-file ignores for pre-existing style insrc/README
-Lexample and a short redirect-following behaviour section