diff --git a/pkg/httputil/httputil.go b/pkg/httputil/httputil.go index 08c30c581..a1d57b2d4 100644 --- a/pkg/httputil/httputil.go +++ b/pkg/httputil/httputil.go @@ -47,7 +47,7 @@ func ErrorRouting(conn http.ResponseWriter, req *http.Request) { func BadRequestError(conn http.ResponseWriter, errorMessage string, args ...interface{}) { conn.WriteHeader(http.StatusBadRequest) log.Printf("Bad request: %s", fmt.Sprintf(errorMessage, args...)) - fmt.Fprintf(conn, "%s\n", errorMessage) + fmt.Fprintf(conn, "

Bad Request

") } func ForbiddenError(conn http.ResponseWriter, errorMessage string, args ...interface{}) { @@ -330,3 +330,7 @@ func CloseBody(rc io.ReadCloser) { } rc.Close() } + +func IsWebsocketUpgrade(req *http.Request) bool { + return req.Method == "GET" && req.Header.Get("Upgrade") == "websocket" +}