mirror of https://github.com/perkeep/perkeep.git
httputil: add IsWebsocketUpgrade, fix BadRequestError inconsistency
Change-Id: I85e34fe4e87c2402fe6ab002bcd374ef0fd41141
This commit is contained in:
parent
1046470614
commit
c179081ab7
|
@ -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"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue