net/http: test intended behavior in TestClientInsecureTransport

This test wasn't testing the HTTP/2 case, because it didn't
set NextProtos in the tls.Config.

Set "Connection: close" on requests to make sure each request
gets a new connection.

Change-Id: I1ef470e7433a602ce88da7bd7eeec502687ea857
Reviewed-on: https://go-review.googlesource.com/c/go/+/655676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Damien Neil 2025-03-06 17:33:27 -08:00 committed by Gopher Robot
parent 64371adcf4
commit 2869d55366

View File

@ -834,8 +834,11 @@ func testClientInsecureTransport(t *testing.T, mode testMode) {
for _, insecure := range []bool{true, false} {
c.Transport.(*Transport).TLSClientConfig = &tls.Config{
InsecureSkipVerify: insecure,
NextProtos: cst.tr.TLSClientConfig.NextProtos,
}
res, err := c.Get(ts.URL)
req, _ := NewRequest("GET", ts.URL, nil)
req.Header.Set("Connection", "close") // don't reuse this connection
res, err := c.Do(req)
if (err == nil) != insecure {
t.Errorf("insecure=%v: got unexpected err=%v", insecure, err)
}