(r *http.Request)
| 957 | } |
| 958 | |
| 959 | func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) { |
| 960 | f.mu.Lock() |
| 961 | fallback := f.host == r.URL.Host |
| 962 | f.mu.Unlock() |
| 963 | |
| 964 | // only fall back if the same host had previously fell back |
| 965 | if !fallback { |
| 966 | resp, err := f.super.RoundTrip(r) |
| 967 | if !isTLSError(err) && !isPortError(err, r.URL.Host) { |
| 968 | return resp, err |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | plainHTTPUrl := *r.URL |
| 973 | plainHTTPUrl.Scheme = "http" |
| 974 | |
| 975 | plainHTTPRequest := *r |
| 976 | plainHTTPRequest.URL = &plainHTTPUrl |
| 977 | |
| 978 | if !fallback { |
| 979 | f.mu.Lock() |
| 980 | if f.host != r.URL.Host { |
| 981 | f.host = r.URL.Host |
| 982 | } |
| 983 | f.mu.Unlock() |
| 984 | |
| 985 | // update body on the second attempt |
| 986 | if r.Body != nil && r.GetBody != nil { |
| 987 | body, err := r.GetBody() |
| 988 | if err != nil { |
| 989 | return nil, err |
| 990 | } |
| 991 | plainHTTPRequest.Body = body |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | return f.super.RoundTrip(&plainHTTPRequest) |
| 996 | } |
| 997 | |
| 998 | func isTLSError(err error) bool { |
| 999 | if err == nil { |
nothing calls this directly
no test coverage detected