diff options
author | Andrew Gerrand <adg@golang.org> | 2010-03-20 10:22:09 +1100 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2010-03-20 10:22:09 +1100 |
commit | daa56c8df4e9f252b850d6ac3203e00376b2e27e (patch) | |
tree | 97edd295bc8c04f1720c03ec8c9c4eb53d8ca029 | |
parent | c3a416a7a94c209bd8a6378aa7c94be14cb673ca (diff) | |
download | golang-daa56c8df4e9f252b850d6ac3203e00376b2e27e.tar.gz |
http: add Error helper function
R=r, rsc
CC=golang-dev
http://codereview.appspot.com/626042
-rw-r--r-- | src/pkg/http/server.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index f0b608dde..39b498a7a 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) } |