Skip to content

Commit

Permalink
Update fallback logic to only fallback with previous host
Browse files Browse the repository at this point in the history
Signed-off-by: Derek McGowan <[email protected]>
  • Loading branch information
dmcgowan committed Feb 1, 2024
1 parent 5ac0a34 commit 31a294c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ func newDefaultTransport() *http.Transport {
}

type httpFallback struct {
super http.RoundTripper
fallback bool
super http.RoundTripper
host string
}

func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
if !f.fallback {
// only fall back if the same host had previously fell back
if f.host != r.URL.Host {
resp, err := f.super.RoundTrip(r)
var tlsErr tls.RecordHeaderError
if errors.As(err, &tlsErr) && string(tlsErr.RecordHeader[:]) == "HTTP/" {
// Server gave HTTP response to HTTPS client
f.fallback = true
f.host = r.URL.Host
} else {
return resp, err
}
Expand Down

0 comments on commit 31a294c

Please sign in to comment.