From 310e0474be4b5f1b38935a55356984167d713ce8 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 15 Jun 2011 11:31:24 +0200 Subject: [PATCH] httputil: add ForbiddenError and RequestEntityTooLargeError Change-Id: Ie013c2b79bd75b3c1ba14f94b334bb009b61c4d3 Signed-off-by: Julien Danjou --- lib/go/camli/httputil/httputil.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/go/camli/httputil/httputil.go b/lib/go/camli/httputil/httputil.go index a0c3926d2..8928027fd 100644 --- a/lib/go/camli/httputil/httputil.go +++ b/lib/go/camli/httputil/httputil.go @@ -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, "

Forbidden

") +} + +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, "

Request entity is too large

") +} + func ServerError(conn http.ResponseWriter, err os.Error) { conn.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(conn, "Server error: %s\n", err)