aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go77
1 files changed, 43 insertions, 34 deletions
diff --git a/server.go b/server.go
index 2531ad0..b6fc341 100644
--- a/server.go
+++ b/server.go
@@ -199,57 +199,44 @@ type Handler interface {
Serve(*ResponseWriter, *Request)
}
-// NotFound replies to the request with the NotFound status code.
-func NotFound(rw *ResponseWriter, req *Request) {
- rw.WriteHeader(StatusNotFound, "Not found")
-}
-
-// NotFoundHandler returns a simple handler that responds to each request with
-// the status code NotFound.
-func NotFoundHandler() Handler {
- return HandlerFunc(NotFound)
-}
-
-// Gone replies to the request with the Gone status code.
-func Gone(rw *ResponseWriter, req *Request) {
- rw.WriteHeader(StatusGone, "Gone")
+// Input responds to the request with a request for input using the given prompt.
+func Input(rw *ResponseWriter, req *Request, prompt string) {
+ rw.WriteHeader(StatusInput, prompt)
}
-// GoneHandler returns a simple handler that responds to each request with
-// the status code Gone.
-func GoneHandler() Handler {
- return HandlerFunc(Gone)
+// InputHandler returns a simple handler that responds to each request with
+// a request for input.
+func InputHandler(prompt string) Handler {
+ return HandlerFunc(func(rw *ResponseWriter, req *Request) {
+ Input(rw, req, prompt)
+ })
}
// Redirect replies to the request with a redirect to the given url.
-// If permanent is true, Redirect will respond with a permanent redirect.
-func Redirect(rw *ResponseWriter, req *Request, url string, permanent bool) {
- if permanent {
- rw.WriteHeader(StatusRedirectPermanent, url)
- } else {
- rw.WriteHeader(StatusRedirect, url)
- }
+func Redirect(rw *ResponseWriter, req *Request, url string) {
+ rw.WriteHeader(StatusRedirect, url)
}
// RedirectHandler returns a simple handler that responds to each request with
// a redirect to the given URL.
// If permanent is true, the handler will respond with a permanent redirect.
-func RedirectHandler(url string, permanent bool) Handler {
+func RedirectHandler(url string) Handler {
return HandlerFunc(func(rw *ResponseWriter, req *Request) {
- Redirect(rw, req, url, permanent)
+ Redirect(rw, req, url)
})
}
-// Input responds to the request with a request for input using the given prompt.
-func Input(rw *ResponseWriter, req *Request, prompt string) {
- rw.WriteHeader(StatusInput, prompt)
+// PermanentRedirect replies to the request with a permanent redirect to the given URL.
+func PermanentRedirect(rw *ResponseWriter, req *Request, url string) {
+ rw.WriteHeader(StatusRedirectPermanent, url)
}
-// InputHandler returns a simple handler that responds to each request with
-// a request for input.
-func InputHandler(prompt string) Handler {
+// PermanentRedirectHandler returns a simple handler that responds to each request with
+// a redirect to the given URL.
+// If permanent is true, the handler will respond with a permanent redirect.
+func PermanentRedirectHandler(url string) Handler {
return HandlerFunc(func(rw *ResponseWriter, req *Request) {
- Input(rw, req, prompt)
+ PermanentRedirect(rw, req, url)
})
}
@@ -279,6 +266,28 @@ func CertificateNotAuthorized(rw *ResponseWriter, req *Request) {
rw.WriteHeader(StatusCertificateNotAuthorized, "Certificate not authorized")
}
+// NotFound replies to the request with the NotFound status code.
+func NotFound(rw *ResponseWriter, req *Request) {
+ rw.WriteHeader(StatusNotFound, "Not found")
+}
+
+// NotFoundHandler returns a simple handler that responds to each request with
+// the status code NotFound.
+func NotFoundHandler() Handler {
+ return HandlerFunc(NotFound)
+}
+
+// Gone replies to the request with the Gone status code.
+func Gone(rw *ResponseWriter, req *Request) {
+ rw.WriteHeader(StatusGone, "Gone")
+}
+
+// GoneHandler returns a simple handler that responds to each request with
+// the status code Gone.
+func GoneHandler() Handler {
+ return HandlerFunc(Gone)
+}
+
// ServeMux is a Gemini request multiplexer.
// It matches the URL of each incoming request against a list of registered
// patterns and calls the handler for the pattern that most closesly matches