(ctx context.Context, endpoint string, headers map[string]string, body any, dst any, timeout time.Duration)
| 107 | Transport: sharedHTTPTransport, |
| 108 | CheckRedirect: sameHostRedirectPolicy, |
| 109 | } |
| 110 | |
| 111 | // sameHostRedirectPolicy 只允许同 scheme + 同 host:port 的重定向,且最多 5 跳。 |
| 112 | // 跨主机直接返回 ErrUseLastResponse —— 调用方拿到的是原始 302 响应(结合 |
| 113 | // `resp.StatusCode >= 400` 检查会被当作非预期状态返回错误,不会出现 token |
| 114 | // 已被发到第三方的窗口)。 |
| 115 | func sameHostRedirectPolicy(req *http.Request, via []*http.Request) error { |
| 116 | if len(via) >= 5 { |
| 117 | return http.ErrUseLastResponse |
| 118 | } |
| 119 | if len(via) == 0 { |
| 120 | return nil |
| 121 | } |
| 122 | prev := via[len(via)-1].URL |
| 123 | next := req.URL |
| 124 | if prev == nil || next == nil { |
| 125 | return http.ErrUseLastResponse |
| 126 | } |
no test coverage detected