httputil: add IsWebsocketUpgrade, fix BadRequestError inconsistency

Change-Id: I85e34fe4e87c2402fe6ab002bcd374ef0fd41141
This commit is contained in:
Brad Fitzpatrick 2014-02-03 20:24:45 -05:00
parent 1046470614
commit c179081ab7
1 changed files with 5 additions and 1 deletions

View File

@ -47,7 +47,7 @@ func ErrorRouting(conn http.ResponseWriter, req *http.Request) {
func BadRequestError(conn http.ResponseWriter, errorMessage string, args ...interface{}) { func BadRequestError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusBadRequest) conn.WriteHeader(http.StatusBadRequest)
log.Printf("Bad request: %s", fmt.Sprintf(errorMessage, args...)) log.Printf("Bad request: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "%s\n", errorMessage) fmt.Fprintf(conn, "<h1>Bad Request</h1>")
} }
func ForbiddenError(conn http.ResponseWriter, errorMessage string, args ...interface{}) { func ForbiddenError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
@ -330,3 +330,7 @@ func CloseBody(rc io.ReadCloser) {
} }
rc.Close() rc.Close()
} }
func IsWebsocketUpgrade(req *http.Request) bool {
return req.Method == "GET" && req.Header.Get("Upgrade") == "websocket"
}