From 4cc29734837f8b448a90da6d55a96d637f0171bc Mon Sep 17 00:00:00 2001 From: Ali Farooq Date: Tue, 29 Oct 2019 06:44:32 -0400 Subject: [PATCH] MM-18827 - Can not use api/v4/websocket with trailing slash (#12931) --- api4/websocket.go | 3 ++- api4/websocket_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api4/websocket.go b/api4/websocket.go index 164ae83b79..85eaf87d39 100644 --- a/api4/websocket.go +++ b/api4/websocket.go @@ -12,7 +12,8 @@ import ( ) func (api *API) InitWebSocket() { - api.BaseRoutes.ApiRoot.Handle("/websocket", api.ApiHandlerTrustRequester(connectWebSocket)).Methods("GET") + // Optionally supports a trailing slash + api.BaseRoutes.ApiRoot.Handle("/{websocket:websocket(?:\\/)?}", api.ApiHandlerTrustRequester(connectWebSocket)).Methods("GET") } func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) { diff --git a/api4/websocket_test.go b/api4/websocket_test.go index 504a7095a3..8450684f7a 100644 --- a/api4/websocket_test.go +++ b/api4/websocket_test.go @@ -66,6 +66,15 @@ func TestWebSocket(t *testing.T) { require.Equal(t, resp.Error.DetailedError, "", "detailed error not cleared") } +func TestWebSocketTrailingSlash(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + + url := fmt.Sprintf("ws://localhost:%v", th.App.Srv.ListenAddr.Port) + _, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket/", nil) + require.NoError(t, err) +} + func TestWebSocketEvent(t *testing.T) { th := Setup().InitBasic() defer th.TearDown()