Skip to content

Commit 2d67618

Browse files
committed
websocketproxy: also test the nilness of backend function
1 parent cd6231c commit 2d67618

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

websocketproxy.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ func NewProxy(target *url.URL) *WebsocketProxy {
5656
return &WebsocketProxy{Backend: backend}
5757
}
5858

59-
func (w *WebsocketProxy) CloseNotify() {
60-
}
61-
6259
// ServeHTTP implements the http.Handler that proxies WebSocket connections.
6360
func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
61+
if w.Backend == nil {
62+
log.Println("websocketproxy: backend function is not defined")
63+
http.Error(rw, "internal server error (code: 1)", http.StatusInternalServerError)
64+
return
65+
}
66+
6467
backendURL := w.Backend(req)
6568
if backendURL == nil {
6669
log.Println("websocketproxy: backend URL is nil")
67-
http.Error(rw, "internal server error", http.StatusInternalServerError)
70+
http.Error(rw, "internal server error (code: 2)", http.StatusInternalServerError)
6871
return
6972
}
7073

0 commit comments

Comments
 (0)