From c179081ab749df9433045ee8ea09f0dbb340faf3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 3 Feb 2014 20:24:45 -0500 Subject: [PATCH] httputil: add IsWebsocketUpgrade, fix BadRequestError inconsistency Change-Id: I85e34fe4e87c2402fe6ab002bcd374ef0fd41141 --- pkg/httputil/httputil.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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" +}