mirror of
https://github.com/mattermost/mattermost.git
synced 2026-03-04 06:11:39 -05:00
* Revert "MM-34000: Use non-epoll mode for TLS connections (#17172)" This reverts commit2743089b54. * Revert "MM-33233: Fix double close of webconn pump (#17026)" This reverts commit0f98620b65. * Revert "MM-33836: Detect and upgrade incorrect HTTP version for websocket handshakes (#17142)" This reverts commit4c5ea07aff. * revert i18n * Revert "MM-21012: Revamp websocket implementation (#16620)" This reverts commita246104d04. * fix go.mod * Trigger CI
39 lines
1 KiB
Go
39 lines
1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
func (api *API) InitWebSocket() {
|
|
// 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) {
|
|
upgrader := websocket.Upgrader{
|
|
ReadBufferSize: model.SOCKET_MAX_MESSAGE_SIZE_KB,
|
|
WriteBufferSize: model.SOCKET_MAX_MESSAGE_SIZE_KB,
|
|
CheckOrigin: c.App.OriginChecker(),
|
|
}
|
|
|
|
ws, err := upgrader.Upgrade(w, r, nil)
|
|
if err != nil {
|
|
c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
wc := c.App.NewWebConn(ws, *c.App.Session(), c.App.T, "")
|
|
|
|
if c.App.Session().UserId != "" {
|
|
c.App.HubRegister(wc)
|
|
}
|
|
|
|
wc.Pump()
|
|
}
|