From: Andrew Gerrand Date: Fri, 19 Mar 2010 23:22:09 +0000 (+1100) Subject: http: add Error helper function X-Git-Tag: weekly.2010-03-22~13 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f4322a848d651a8cc8bf5ec9a762e3dbca7ed784;p=gostls13.git http: add Error helper function R=r, rsc CC=golang-dev https://golang.org/cl/626042 --- diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index f0b608ddeb..39b498a7ac 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -328,13 +328,16 @@ func (f HandlerFunc) ServeHTTP(c *Conn, req *Request) { // Helper handlers -// NotFound replies to the request with an HTTP 404 not found error. -func NotFound(c *Conn, req *Request) { +// Error replies to the request with the specified error message and HTTP code. +func Error(c *Conn, error string, code int) { c.SetHeader("Content-Type", "text/plain; charset=utf-8") - c.WriteHeader(StatusNotFound) - io.WriteString(c, "404 page not found\n") + c.WriteHeader(code) + fmt.Fprintln(c, error) } +// NotFound replies to the request with an HTTP 404 not found error. +func NotFound(c *Conn, req *Request) { Error(c, "404 page not found", StatusNotFound) } + // NotFoundHandler returns a simple request handler // that replies to each request with a ``404 page not found'' reply. func NotFoundHandler() Handler { return HandlerFunc(NotFound) }