File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"path/filepath"
11
11
"runtime"
12
12
"strings"
13
+ "sync"
13
14
"syscall"
14
15
"time"
15
16
@@ -213,13 +214,18 @@ func newDefaultTransport() *http.Transport {
213
214
}
214
215
215
216
type httpFallback struct {
216
- super http.RoundTripper
217
- host string
217
+ super http.RoundTripper
218
+ host string
219
+ hostMut sync.Mutex
218
220
}
219
221
220
222
func (f * httpFallback ) RoundTrip (r * http.Request ) (* http.Response , error ) {
221
- // only fall back if the same host had previously fell back
222
- if f .host != r .URL .Host {
223
+ f .hostMut .Lock ()
224
+ // Skip the HTTPS call only if the same host had previously fell back
225
+ tryHTTPSFirst := f .host != r .URL .Host
226
+ f .hostMut .Unlock ()
227
+
228
+ if tryHTTPSFirst {
223
229
resp , err := f .super .RoundTrip (r )
224
230
if ! isTLSError (err ) && ! isPortError (err , r .URL .Host ) {
225
231
return resp , err
@@ -232,8 +238,13 @@ func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
232
238
plainHTTPRequest := * r
233
239
plainHTTPRequest .URL = & plainHTTPUrl
234
240
235
- if f .host != r .URL .Host {
241
+ // We tried HTTPS first but it failed.
242
+ // Mark the host so we don't try HTTPS for this host next time
243
+ // and refresh the request body.
244
+ if tryHTTPSFirst {
245
+ f .hostMut .Lock ()
236
246
f .host = r .URL .Host
247
+ f .hostMut .Unlock ()
237
248
238
249
// update body on the second attempt
239
250
if r .Body != nil && r .GetBody != nil {
You can’t perform that action at this time.
0 commit comments