Skip to content

feat: add option to follow only same-host redirects - #557

Merged
dwisiswant0 merged 1 commit into
mainfrom
dwisiswant0/feat/add-option-to-follow-only-same-host-redirects
Nov 4, 2026
Merged

dwisiswant0 merged 1 commit into
mainfrom
dwisiswant0/feat/add-option-to-follow-only-same-host-redirects

Conversation

@dwisiswant0

Copy link
Copy Markdown
Member

With redirects on, the client followed a 3xx to whatever host and
scheme the Location header named and resent the caller's headers,
Authorization included. Nothing in Options could restrict that, so
callers that want same-host redirects, such as nuclei's host-redirects
and httpx's -follow-host-redirects, could only pick all redirects or
none on the rawhttp path.

Options.FollowHostRedirects follows a redirect only when the next
request would connect to the same protocol and host:port as the
current one. Otherwise do returns the redirect response unread. The
check goes through dialTarget, the helper do now uses to choose the
connection, so it compares exactly what would be dialed. Hosts must
match byte for byte, because Unicode case folding maps some distinct
hostnames, such as "ſecret.com", onto ASCII ones. As with the
host-redirect options in nuclei and httpx, setting it also enables
following when FollowRedirects is false.

Closes: #556

With redirects on, the client followed a 3xx to whatever host and
scheme the Location header named and resent the caller's headers,
Authorization included. Nothing in Options could restrict that, so
callers that want same-host redirects, such as nuclei's host-redirects
and httpx's -follow-host-redirects, could only pick all redirects or
none on the rawhttp path.

Options.FollowHostRedirects follows a redirect only when the next
request would connect to the same protocol and host:port as the
current one. Otherwise do returns the redirect response unread. The
check goes through dialTarget, the helper do now uses to choose the
connection, so it compares exactly what would be dialed. Hosts must
match byte for byte, because Unicode case folding maps some distinct
hostnames, such as "ſecret.com", onto ASCII ones. As with the
host-redirect options in nuclei and httpx, setting it also enables
following when FollowRedirects is false.

Closes: #556
Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 requested a review from Mzack9999 November 4, 2026 05:20
@dwisiswant0
dwisiswant0 merged commit 3504c07 into main Nov 4, 2026
6 checks passed
@dwisiswant0
dwisiswant0 deleted the dwisiswant0/feat/add-option-to-follow-only-same-host-redirects branch November 4, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to follow redirects only to the same host

2 participants