Return 404 for WS handler when session doesnt exist

This commit is contained in:
Marcos Lilljedahl
2017-07-31 18:20:27 -03:00
parent fa3b56ecfe
commit 7a49c557e0
4 changed files with 20 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package handlers
import (
"fmt"
"log"
"net/http"
"github.com/googollee/go-socket.io"
"github.com/gorilla/mux"
@@ -52,3 +53,16 @@ func WS(so socketio.Socket) {
func WSError(so socketio.Socket) {
log.Println("error ws")
}
func WebSocket(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
sessionId := vars["sessionId"]
session := core.SessionGet(sessionId)
if session == nil {
rw.WriteHeader(http.StatusNotFound)
return
}
broadcast.GetHandler().ServeHTTP(rw, req)
}