Skip to content

http-connect: error to be written on connection #640

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/server/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, "hijacking not supported", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)

conn, bufrw, err := hijacker.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Send the HTTP 200 OK status after a successful hijack
_, err = conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))
if err != nil {
klog.ErrorS(err, "failed to send 200 connection established")
conn.Close()
return
}

var closeOnce sync.Once
defer closeOnce.Do(func() { conn.Close() })

Expand All @@ -78,7 +86,9 @@ func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
klog.V(4).Infof("Set pending(rand=%d) to %v", random, w)
backend, err := t.Server.getBackend(r.Host)
if err != nil {
http.Error(w, fmt.Sprintf("currently no tunnels available: %v", err), http.StatusInternalServerError)
klog.ErrorS(err, "no tunnels available")
conn.Write([]byte(fmt.Sprintf("HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/plain\r\n\r\ncurrently no tunnels available: %v", err)))
conn.Close()
return
}
closed := make(chan struct{})
Expand Down