Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create stream to endpoint that uses SPDY/3.1 #28

Open
g3rzi opened this issue Apr 4, 2020 · 1 comment
Open

Can't create stream to endpoint that uses SPDY/3.1 #28

g3rzi opened this issue Apr 4, 2020 · 1 comment

Comments

@g3rzi
Copy link

g3rzi commented Apr 4, 2020

Hi,

I am trying to execute commands on kubelet agent in Kubernetes cluster and it uses SPDY/3.1.
When I run this function:

func PostRequest(client *http.Client, bodyData []byte) (*http.Response, error){
        url := "https://<node_ip>:10250/exec/default/nginxPod/nginx?command=ls&command=/&input=1&output=1&tty=0"
	req, _ := http.NewRequest("POST", url, bytes.NewBuffer(bodyData))
	req.Header.Set("X-Stream-Protocol-Version", "v2.channel.k8s.io")
	req.Header.Set("X-Stream-Protocol-Version", "channel.k8s.io")
	req.Header.Set("Upgrade", "SPDY/3.1")
	req.Header.Set("Connection","upgrade")
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

	resp, err := (*client).Do(req)

	return resp, err
}

The status of resp is 101 Switching Protocols. I can't read it, because if I will try it will stuck:

bodyBytes, _ := ioutil.ReadAll(r.Body)

So I used your library with the following code (I took it from your example):

url2 := "https://123.123.123.123:10250/exec/default/mypod/mycontainer?command=ls&command=/&input=1&output=1&tty=1"
client, err := spdy.NewClient("123.123.123.123:10250")
if err != nil {
	//handle error here
}
req, err := http.NewRequest("POST", url2, nil)
if err != nil {
	//handle error here
}

req.Header.Set("X-Stream-Protocol-Version", "v2.channel.k8s.io")
req.Header.Set("X-Stream-Protocol-Version", "channel.k8s.io")
req.Header.Set("Upgrade", "SPDY/3.1")
req.Header.Set("Connection","upgrade")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

//now send the request to obtain a http response
res, err := client.Do(req)
if err != nil {
	//something went wrong
}

//now handle the response
data := make([]byte, int(res.ContentLength))
_, err = res.Body.(io.Reader).Read(data)
fmt.Println(string(data))
fmt.Println(res.Header)
res.Body.Close()

After I run it, it failed with the following errors:

[SPDY] 2020/04/04 23:07:35 session.go:197: WARN: communication error: use of closed network connection
[SPDY] 2020/04/04 23:07:35 proxy.go:20: ERROR in NewClientStream: cannot create stream
404 page not found

Any idea why it failed?
With my function it returned the 101 status but with your it returns 404.

@wenzj-code
Copy link

Hi,

I am trying to execute commands on kubelet agent in Kubernetes cluster and it uses SPDY/3.1.
When I run this function:

func PostRequest(client *http.Client, bodyData []byte) (*http.Response, error){
        url := "https://<node_ip>:10250/exec/default/nginxPod/nginx?command=ls&command=/&input=1&output=1&tty=0"
	req, _ := http.NewRequest("POST", url, bytes.NewBuffer(bodyData))
	req.Header.Set("X-Stream-Protocol-Version", "v2.channel.k8s.io")
	req.Header.Set("X-Stream-Protocol-Version", "channel.k8s.io")
	req.Header.Set("Upgrade", "SPDY/3.1")
	req.Header.Set("Connection","upgrade")
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

	resp, err := (*client).Do(req)

	return resp, err
}

The status of resp is 101 Switching Protocols. I can't read it, because if I will try it will stuck:

bodyBytes, _ := ioutil.ReadAll(r.Body)

So I used your library with the following code (I took it from your example):

url2 := "https://123.123.123.123:10250/exec/default/mypod/mycontainer?command=ls&command=/&input=1&output=1&tty=1"
client, err := spdy.NewClient("123.123.123.123:10250")
if err != nil {
	//handle error here
}
req, err := http.NewRequest("POST", url2, nil)
if err != nil {
	//handle error here
}

req.Header.Set("X-Stream-Protocol-Version", "v2.channel.k8s.io")
req.Header.Set("X-Stream-Protocol-Version", "channel.k8s.io")
req.Header.Set("Upgrade", "SPDY/3.1")
req.Header.Set("Connection","upgrade")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

//now send the request to obtain a http response
res, err := client.Do(req)
if err != nil {
	//something went wrong
}

//now handle the response
data := make([]byte, int(res.ContentLength))
_, err = res.Body.(io.Reader).Read(data)
fmt.Println(string(data))
fmt.Println(res.Header)
res.Body.Close()

After I run it, it failed with the following errors:

[SPDY] 2020/04/04 23:07:35 session.go:197: WARN: communication error: use of closed network connection
[SPDY] 2020/04/04 23:07:35 proxy.go:20: ERROR in NewClientStream: cannot create stream
404 page not found

Any idea why it failed?
With my function it returned the 101 status but with your it returns 404.

Do you solve this question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants