inital commit
This commit is contained in:
11
transport.go
11
transport.go
@@ -32,6 +32,17 @@ const defaultMaxRetries = 3
|
||||
// injects the User-Agent header, retries on transient failures, and
|
||||
// classifies Cloudflare challenges as non-retryable user-actionable errors.
|
||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if ov := requestOverrideFrom(req.Context()); ov != nil {
|
||||
if ov.userAgent != "" {
|
||||
req.Header.Set("User-Agent", ov.userAgent)
|
||||
}
|
||||
if ov.touchesCookies() {
|
||||
// The cookie jar already wrote a Cookie header by the time we
|
||||
// reach RoundTrip; replace it wholesale so per-user creds win
|
||||
// over whatever the shared jar would inject.
|
||||
req.Header.Set("Cookie", ov.cookieHeader())
|
||||
}
|
||||
}
|
||||
if t.userAgent != "" && req.Header.Get("User-Agent") == "" {
|
||||
req.Header.Set("User-Agent", t.userAgent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user