@@ -53,13 +53,21 @@ func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5353 http .Error (w , "hijacking not supported" , http .StatusInternalServerError )
5454 return
5555 }
56- w .WriteHeader (http .StatusOK )
5756
5857 conn , bufrw , err := hijacker .Hijack ()
5958 if err != nil {
6059 http .Error (w , err .Error (), http .StatusInternalServerError )
6160 return
6261 }
62+
63+ // Send the HTTP 200 OK status after a successful hijack
64+ _ , err = conn .Write ([]byte ("HTTP/1.1 200 Connection Established\r \n \r \n " ))
65+ if err != nil {
66+ klog .ErrorS (err , "failed to send 200 connection established" )
67+ conn .Close ()
68+ return
69+ }
70+
6371 var closeOnce sync.Once
6472 defer closeOnce .Do (func () { conn .Close () })
6573
@@ -78,7 +86,9 @@ func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7886 klog .V (4 ).Infof ("Set pending(rand=%d) to %v" , random , w )
7987 backend , err := t .Server .getBackend (r .Host )
8088 if err != nil {
81- http .Error (w , fmt .Sprintf ("currently no tunnels available: %v" , err ), http .StatusInternalServerError )
89+ klog .ErrorS (err , "no tunnels available" )
90+ conn .Write ([]byte (fmt .Sprintf ("HTTP/1.1 500 Internal Server Error\r \n Content-Type: text/plain\r \n \r \n currently no tunnels available: %v" , err )))
91+ conn .Close ()
8292 return
8393 }
8494 closed := make (chan struct {})
0 commit comments