Add redirect-chain rules per RFC 9110 §15.4

This commit is contained in:
nemunaire 2026-04-27 10:09:21 +07:00
commit 27a30638f4
3 changed files with 416 additions and 1 deletions

View file

@ -221,10 +221,16 @@ func runProbe(ctx context.Context, host, ip, scheme string, port uint16, timeout
// and a separate http.Client.Timeout would race with it.
CheckRedirect: func(req *http.Request, via []*http.Request) error {
prev := via[len(via)-1]
// req.Response is the 3xx response that triggered this hop;
// it carries the redirecting status code (301/302/307/308…).
status := 0
if req.Response != nil {
status = req.Response.StatusCode
}
redirectChain = append(redirectChain, RedirectStep{
From: prev.URL.String(),
To: req.URL.String(),
Status: 0, // populated post-hoc below if available
Status: status,
})
// The transport's DialContext is pinned to the original
// (ip, port) and TLS ServerName is pinned to the original