feat(redirects): add --follow-redirects / --no-follow-redirects / --max-redirects (#13)#17
Merged
Merged
Conversation
…ax-redirects kurl always followed redirects with a hardcoded cap of 10 and no way to opt out, so inspecting a 301/302 response (common when debugging auth flows or shorteners) was impossible. Add explicit control, mirroring curl's -L / --max-redirs: --follow-redirects follow 3xx (default, unchanged behaviour) --no-follow-redirects return the redirect response itself, unfollowed --max-redirects N cap the number of redirects followed (default 10) Implementation: - client.Options gains FollowRedirects and MaxRedirects. When not following, the first 3xx response is returned as-is; when following, the manual redirect loop now respects MaxRedirects instead of the hardcoded 10 and reports a clear "stopped after N redirects" error. - Flags parsed in main.go (both "--flag value" and "--flag=value" forms), seeded via a shared baseOptions() helper so CLI, save and run agree on defaults. Saved requests persist the settings; FollowRedirects is stored as a pointer so older saved files without the field still default to true. - The redirect chain is already shown in verbose output via Result.Redirects, which is still populated when following. - Help text updated. Tests: CLI flag parsing (defaults, both spellings, invalid values) and client behaviour (follows + records hops, no-follow returns the 3xx, max-redirects exceeded errors). All packages pass via `go test ./...`. Closes #13 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kavix
approved these changes
Jun 13, 2026
Owner
|
@copilot resolve the merge conflicts in this pull request |
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.
Description
Fixes #13.
kurl always followed redirects with a hardcoded cap of 10 and no way to opt out, so inspecting a
301/302response directly (common when debugging auth flows or URL shorteners) wasn't possible. This adds explicit control, mirroring curl's-L/--max-redirs:--follow-redirects--no-follow-redirects--max-redirects NImplementation
client.OptionsgainsFollowRedirectsandMaxRedirects. When not following, the first 3xx response is returned as-is so the caller can inspect status +Location. When following, the existing manual redirect loop now respectsMaxRedirectsinstead of the hardcoded10, and reports a clearstopped after N redirects (raise with --max-redirects, or use --no-follow-redirects)error.main.go(both--flag valueand--flag=valueforms), seeded via a sharedbaseOptions()helper so the CLI,save, andrunpaths agree on defaults.FollowRedirectsis stored as a*boolso older saved files without the field still default to follow (not the bool zero value).Result.Redirects, which is still populated when following.Maps to the issue's acceptance criteria:
--follow-redirectsflag (default true, backward compatible)--no-follow-redirectsflag--max-redirectsflag with a sensible default (10)Result.Redirects)Type of change
How Has This Been Tested?
main_test.go: defaults, both spellings, invalid values) and client behaviour (client/redirect_test.go: follows + records hops, no-follow returns the 3xx, max-redirects exceeded errors).go test ./...locally — all packages pass.kurl --no-follow-redirects http://github.com→ shows301 Moved Permanentlyinstead of followingkurl --max-redirects abc …→invalid max-redirects "abc": want a non-negative integerChecklist
gofmt,go vetclean)