Skip to content

Commit 1358eff

Browse files
committed
http2: fix all vet warnings
Updates golang/go#16228 Updates golang/go#11041 Change-Id: I2b50c2f4bfaae2d9ad59bc78e1c7c3e807f08075 Reviewed-on: https://go-review.googlesource.com/28344 Run-TryBot: Brad Fitzpatrick <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9bc2a33 commit 1358eff

File tree

6 files changed

+90
-25
lines changed

6 files changed

+90
-25
lines changed

http2/go17_not18.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build go1.7,!go1.8
6+
7+
package http2
8+
9+
import "crypto/tls"
10+
11+
// temporary copy of Go 1.7's private tls.Config.clone:
12+
func cloneTLSConfig(c *tls.Config) *tls.Config {
13+
return &tls.Config{
14+
Rand: c.Rand,
15+
Time: c.Time,
16+
Certificates: c.Certificates,
17+
NameToCertificate: c.NameToCertificate,
18+
GetCertificate: c.GetCertificate,
19+
RootCAs: c.RootCAs,
20+
NextProtos: c.NextProtos,
21+
ServerName: c.ServerName,
22+
ClientAuth: c.ClientAuth,
23+
ClientCAs: c.ClientCAs,
24+
InsecureSkipVerify: c.InsecureSkipVerify,
25+
CipherSuites: c.CipherSuites,
26+
PreferServerCipherSuites: c.PreferServerCipherSuites,
27+
SessionTicketsDisabled: c.SessionTicketsDisabled,
28+
SessionTicketKey: c.SessionTicketKey,
29+
ClientSessionCache: c.ClientSessionCache,
30+
MinVersion: c.MinVersion,
31+
MaxVersion: c.MaxVersion,
32+
CurvePreferences: c.CurvePreferences,
33+
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
34+
Renegotiation: c.Renegotiation,
35+
}
36+
}

http2/go18.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build go1.8
6+
7+
package http2
8+
9+
import "crypto/tls"
10+
11+
func cloneTLSConfig(c *tls.Config) *tls.Config { return c.Clone() }

http2/not_go17.go

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package http2
88

99
import (
10+
"crypto/tls"
1011
"net"
1112
"net/http"
1213
)
@@ -49,3 +50,28 @@ func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) {
4950
func requestWithContext(req *http.Request, ctx contextContext) *http.Request {
5051
return req
5152
}
53+
54+
// temporary copy of Go 1.6's private tls.Config.clone:
55+
func cloneTLSConfig(c *tls.Config) *tls.Config {
56+
return &tls.Config{
57+
Rand: c.Rand,
58+
Time: c.Time,
59+
Certificates: c.Certificates,
60+
NameToCertificate: c.NameToCertificate,
61+
GetCertificate: c.GetCertificate,
62+
RootCAs: c.RootCAs,
63+
NextProtos: c.NextProtos,
64+
ServerName: c.ServerName,
65+
ClientAuth: c.ClientAuth,
66+
ClientCAs: c.ClientCAs,
67+
InsecureSkipVerify: c.InsecureSkipVerify,
68+
CipherSuites: c.CipherSuites,
69+
PreferServerCipherSuites: c.PreferServerCipherSuites,
70+
SessionTicketsDisabled: c.SessionTicketsDisabled,
71+
SessionTicketKey: c.SessionTicketKey,
72+
ClientSessionCache: c.ClientSessionCache,
73+
MinVersion: c.MinVersion,
74+
MaxVersion: c.MaxVersion,
75+
CurvePreferences: c.CurvePreferences,
76+
}
77+
}

http2/server_test.go

+14-22
Original file line numberDiff line numberDiff line change
@@ -2931,51 +2931,43 @@ func (c *issue53Conn) SetWriteDeadline(t time.Time) error { return nil }
29312931
// golang.org/issue/12895
29322932
func TestConfigureServer(t *testing.T) {
29332933
tests := []struct {
2934-
name string
2935-
in http.Server
2936-
wantErr string
2934+
name string
2935+
tlsConfig *tls.Config
2936+
wantErr string
29372937
}{
29382938
{
29392939
name: "empty server",
2940-
in: http.Server{},
29412940
},
29422941
{
29432942
name: "just the required cipher suite",
2944-
in: http.Server{
2945-
TLSConfig: &tls.Config{
2946-
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2947-
},
2943+
tlsConfig: &tls.Config{
2944+
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
29482945
},
29492946
},
29502947
{
29512948
name: "missing required cipher suite",
2952-
in: http.Server{
2953-
TLSConfig: &tls.Config{
2954-
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
2955-
},
2949+
tlsConfig: &tls.Config{
2950+
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
29562951
},
29572952
wantErr: "is missing HTTP/2-required TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
29582953
},
29592954
{
29602955
name: "required after bad",
2961-
in: http.Server{
2962-
TLSConfig: &tls.Config{
2963-
CipherSuites: []uint16{tls.TLS_RSA_WITH_RC4_128_SHA, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2964-
},
2956+
tlsConfig: &tls.Config{
2957+
CipherSuites: []uint16{tls.TLS_RSA_WITH_RC4_128_SHA, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
29652958
},
29662959
wantErr: "contains an HTTP/2-approved cipher suite (0xc02f), but it comes after",
29672960
},
29682961
{
29692962
name: "bad after required",
2970-
in: http.Server{
2971-
TLSConfig: &tls.Config{
2972-
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_RSA_WITH_RC4_128_SHA},
2973-
},
2963+
tlsConfig: &tls.Config{
2964+
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_RSA_WITH_RC4_128_SHA},
29742965
},
29752966
},
29762967
}
29772968
for _, tt := range tests {
2978-
err := ConfigureServer(&tt.in, nil)
2969+
srv := &http.Server{TLSConfig: tt.tlsConfig}
2970+
err := ConfigureServer(srv, nil)
29792971
if (err != nil) != (tt.wantErr != "") {
29802972
if tt.wantErr != "" {
29812973
t.Errorf("%s: success, but want error", tt.name)
@@ -2986,7 +2978,7 @@ func TestConfigureServer(t *testing.T) {
29862978
if err != nil && tt.wantErr != "" && !strings.Contains(err.Error(), tt.wantErr) {
29872979
t.Errorf("%s: err = %v; want substring %q", tt.name, err, tt.wantErr)
29882980
}
2989-
if err == nil && !tt.in.TLSConfig.PreferServerCipherSuites {
2981+
if err == nil && !srv.TLSConfig.PreferServerCipherSuites {
29902982
t.Errorf("%s: PreferServerCipherSuite is false; want true", tt.name)
29912983
}
29922984
}

http2/transport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (t *Transport) dialClientConn(addr string, singleUse bool) (*ClientConn, er
356356
func (t *Transport) newTLSConfig(host string) *tls.Config {
357357
cfg := new(tls.Config)
358358
if t.TLSClientConfig != nil {
359-
*cfg = *t.TLSClientConfig
359+
*cfg = *cloneTLSConfig(t.TLSClientConfig)
360360
}
361361
if !strSliceContains(cfg.NextProtos, NextProtoTLS) {
362362
cfg.NextProtos = append([]string{NextProtoTLS}, cfg.NextProtos...)

http2/transport_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func TestConfigureTransport(t *testing.T) {
510510
if err != nil {
511511
t.Fatal(err)
512512
}
513-
if got := fmt.Sprintf("%#v", *t1); !strings.Contains(got, `"h2"`) {
513+
if got := fmt.Sprintf("%#v", t1); !strings.Contains(got, `"h2"`) {
514514
// Laziness, to avoid buildtags.
515515
t.Errorf("stringification of HTTP/1 transport didn't contain \"h2\": %v", got)
516516
}
@@ -2105,7 +2105,7 @@ func testTransportUsesGoAwayDebugError(t *testing.T, failMidBody bool) {
21052105
DebugData: goAwayDebugData,
21062106
}
21072107
if !reflect.DeepEqual(err, want) {
2108-
t.Errorf("RoundTrip error = %T: %#v, want %T (%#T)", err, err, want, want)
2108+
t.Errorf("RoundTrip error = %T: %#v, want %T (%#v)", err, err, want, want)
21092109
}
21102110
return nil
21112111
}

0 commit comments

Comments
 (0)