mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Allow client.Config to be used for HTTP2 and WebSocket connections
client.Config describes how to make a client connection to a server
for HTTP traffic, but for connection upgrade scenarios cannot be
used because the underlying http.Transport object can't allow the
connection to be hijacked. Reorganize the TLS and connection wrapper
methods so that a sophisticated client can do:
cfg := &client.Config{...} // from somewhere
tlsConfig, _ := client.TLSConfigFor(cfg)
_ := conn.Dial(...)
rt := MyRoundTripper() // some func that implements grabbing requests
wrapper, _ := client.HTTPWrappersFor(cfg)
req := &http.Request{}
req.Header.Set("Connection-Upgrade", ...)
_, := wrapper.RoundTrip(req)
// rt has been invoked with a fully formed Req with auth
rt.Req.Write(conn)
// read response for upgrade
It would be good to have utility function that does more of this,
but mostly enabling the HTTP2/SPDY client exec function right now.
This commit is contained in:
@@ -104,54 +104,68 @@ func TestTransportFor(t *testing.T) {
|
||||
"ca transport": {
|
||||
TLS: true,
|
||||
Config: &Config{
|
||||
CAData: []byte(rootCACert),
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CAData: []byte(rootCACert),
|
||||
},
|
||||
},
|
||||
},
|
||||
"bad ca file transport": {
|
||||
Err: true,
|
||||
Config: &Config{
|
||||
CAFile: "invalid file",
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CAFile: "invalid file",
|
||||
},
|
||||
},
|
||||
},
|
||||
"ca data overriding bad ca file transport": {
|
||||
TLS: true,
|
||||
Config: &Config{
|
||||
CAData: []byte(rootCACert),
|
||||
CAFile: "invalid file",
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CAData: []byte(rootCACert),
|
||||
CAFile: "invalid file",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"cert transport": {
|
||||
TLS: true,
|
||||
Config: &Config{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte(keyData),
|
||||
CAData: []byte(rootCACert),
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte(keyData),
|
||||
CAData: []byte(rootCACert),
|
||||
},
|
||||
},
|
||||
},
|
||||
"bad cert data transport": {
|
||||
Err: true,
|
||||
Config: &Config{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte("bad key data"),
|
||||
CAData: []byte(rootCACert),
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte("bad key data"),
|
||||
CAData: []byte(rootCACert),
|
||||
},
|
||||
},
|
||||
},
|
||||
"bad file cert transport": {
|
||||
Err: true,
|
||||
Config: &Config{
|
||||
CertData: []byte(certData),
|
||||
KeyFile: "invalid file",
|
||||
CAData: []byte(rootCACert),
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertData: []byte(certData),
|
||||
KeyFile: "invalid file",
|
||||
CAData: []byte(rootCACert),
|
||||
},
|
||||
},
|
||||
},
|
||||
"key data overriding bad file cert transport": {
|
||||
TLS: true,
|
||||
Config: &Config{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte(keyData),
|
||||
KeyFile: "invalid file",
|
||||
CAData: []byte(rootCACert),
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertData: []byte(certData),
|
||||
KeyData: []byte(keyData),
|
||||
KeyFile: "invalid file",
|
||||
CAData: []byte(rootCACert),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -206,15 +220,19 @@ func TestIsConfigTransportTLS(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Config: &Config{
|
||||
Host: "localhost",
|
||||
CertFile: "foo",
|
||||
Host: "localhost",
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertFile: "foo",
|
||||
},
|
||||
},
|
||||
TransportTLS: true,
|
||||
},
|
||||
{
|
||||
Config: &Config{
|
||||
Host: "///:://localhost",
|
||||
CertFile: "foo",
|
||||
Host: "///:://localhost",
|
||||
TLSClientConfig: TLSClientConfig{
|
||||
CertFile: "foo",
|
||||
},
|
||||
},
|
||||
TransportTLS: false,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user