aboutsummaryrefslogtreecommitdiff
path: root/src/lib/http/server.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-04-14 20:31:31 -0700
committerRuss Cox <rsc@golang.org>2009-04-14 20:31:31 -0700
commitfa6022607351616844bb063c312f52bc7912cbc2 (patch)
tree0f099eaf4e1291cb0aa7bdfa5fb3edfbcc1bb00a /src/lib/http/server.go
parentc956e909136df153750b1409697763d17b5ce63a (diff)
downloadgo-fa6022607351616844bb063c312f52bc7912cbc2.tar.xz
http additions
file system server add NotFound, Redirect functions method on a string R=r DELTA=212 (199 added, 4 deleted, 9 changed) OCL=27467 CL=27471
Diffstat (limited to 'src/lib/http/server.go')
-rw-r--r--src/lib/http/server.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/lib/http/server.go b/src/lib/http/server.go
index fa29e9bc1c..a8aef01f0e 100644
--- a/src/lib/http/server.go
+++ b/src/lib/http/server.go
@@ -253,8 +253,8 @@ func (f HandlerFunc) ServeHTTP(c *Conn, req *Request) {
// Helper handlers
-// 404 not found
-func notFound(c *Conn, req *Request) {
+// NotFound replies to the request with an HTTP 404 not found error.
+func NotFound(c *Conn, req *Request) {
c.SetHeader("Content-Type", "text/plain; charset=utf-8");
c.WriteHeader(StatusNotFound);
io.WriteString(c, "404 page not found\n");
@@ -263,22 +263,26 @@ func notFound(c *Conn, req *Request) {
// NotFoundHandler returns a simple request handler
// that replies to each request with a ``404 page not found'' reply.
func NotFoundHandler() Handler {
- return HandlerFunc(notFound)
+ return HandlerFunc(NotFound)
}
-// Redirect to a fixed URL
-type redirectHandler struct {
- to string;
-}
-func (h *redirectHandler) ServeHTTP(c *Conn, req *Request) {
- c.SetHeader("Location", h.to);
+// Redirect replies to the request with a redirect to url,
+// which may be a path relative to the request path.
+func Redirect(c *Conn, url string) {
+ c.SetHeader("Location", url);
c.WriteHeader(StatusMovedPermanently);
}
+// Redirect to a fixed URL
+type redirectHandler string
+func (url redirectHandler) ServeHTTP(c *Conn, req *Request) {
+ Redirect(c, url);
+}
+
// RedirectHandler returns a request handler that redirects
// each request it receives to the given url.
func RedirectHandler(url string) Handler {
- return &redirectHandler{url};
+ return redirectHandler(url);
}
// ServeMux is an HTTP request multiplexer.