httputil: add ForbiddenError and RequestEntityTooLargeError

Change-Id: Ie013c2b79bd75b3c1ba14f94b334bb009b61c4d3
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2011-06-15 11:31:24 +02:00
parent 6f2af62b81
commit 310e0474be
1 changed files with 14 additions and 2 deletions

View File

@ -30,12 +30,24 @@ func ErrorRouting(conn http.ResponseWriter, req *http.Request) {
log.Printf("Internal routing error on %q", req.URL.Path)
}
func BadRequestError(conn http.ResponseWriter, errorMessage string) {
func BadRequestError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusBadRequest)
log.Printf("Bad request: %s", errorMessage)
log.Printf("Bad request: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "%s\n", errorMessage)
}
func ForbiddenError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusForbidden)
log.Printf("Forbidden: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "<h1>Forbidden</h1>")
}
func RequestEntityTooLargeError(conn http.ResponseWriter, errorMessage string, args ...interface{}) {
conn.WriteHeader(http.StatusForbidden)
log.Printf("Request entity is too large: %s", fmt.Sprintf(errorMessage, args...))
fmt.Fprintf(conn, "<h1>Request entity is too large</h1>")
}
func ServerError(conn http.ResponseWriter, err os.Error) {
conn.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(conn, "Server error: %s\n", err)