Commit 541935b1 authored by Cao Shufeng's avatar Cao Shufeng

fix invalid status code for hijacker

When using hijacker to take over the connection, the http status code should be 101 not 200. PS: Use "kubectl exec" as an example to review this change.
parent b8c9ee8a
...@@ -183,7 +183,7 @@ func (a *auditResponseWriter) processCode(code int) { ...@@ -183,7 +183,7 @@ func (a *auditResponseWriter) processCode(code int) {
} }
func (a *auditResponseWriter) Write(bs []byte) (int, error) { func (a *auditResponseWriter) Write(bs []byte) (int, error) {
a.processCode(200) // the Go library calls WriteHeader internally if no code was written yet. But this will go unnoticed for us a.processCode(http.StatusOK) // the Go library calls WriteHeader internally if no code was written yet. But this will go unnoticed for us
return a.ResponseWriter.Write(bs) return a.ResponseWriter.Write(bs)
} }
...@@ -208,6 +208,8 @@ func (f *fancyResponseWriterDelegator) Flush() { ...@@ -208,6 +208,8 @@ func (f *fancyResponseWriterDelegator) Flush() {
} }
func (f *fancyResponseWriterDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) { func (f *fancyResponseWriterDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) {
// fake a response status before protocol switch happens
f.processCode(http.StatusSwitchingProtocols)
return f.ResponseWriter.(http.Hijacker).Hijack() return f.ResponseWriter.(http.Hijacker).Hijack()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment