From 62efe1e6dccf2d6d19b837085a5b853519afba84 Mon Sep 17 00:00:00 2001 From: roc Date: Tue, 17 May 2022 15:17:26 +0800 Subject: [PATCH] Let EnableForceHTTP1 also take effect when called when there is already an http2 connection --- transport.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/transport.go b/transport.go index 2dd2006c..24d60420 100644 --- a/transport.go +++ b/transport.go @@ -525,14 +525,16 @@ func (t *Transport) roundTrip(req *http.Request) (*http.Response, error) { cancelKey := cancelKey{origReq} req = setupRewindBody(req) - if altRT := t.alternateRoundTripper(req); altRT != nil { - if resp, err := altRT.RoundTrip(req); err != http.ErrSkipAltProtocol { - return resp, err - } - var err error - req, err = rewindBody(req) - if err != nil { - return nil, err + if t.ForceHttpVersion != HTTP1 { + if altRT := t.alternateRoundTripper(req); altRT != nil { + if resp, err := altRT.RoundTrip(req); err != http.ErrSkipAltProtocol { + return resp, err + } + var err error + req, err = rewindBody(req) + if err != nil { + return nil, err + } } } if !isHTTP { @@ -576,7 +578,7 @@ func (t *Transport) roundTrip(req *http.Request) (*http.Response, error) { } var resp *http.Response - if pconn.alt != nil { + if t.ForceHttpVersion != HTTP1 && pconn.alt != nil { // HTTP/2 path. t.setReqCanceler(cancelKey, nil) // not cancelable with CancelRequest resp, err = pconn.alt.RoundTrip(req)