Add helper handler functions
This commit is contained in:
parent
73e4ef0689
commit
a4a8d49ca7
|
@ -77,9 +77,8 @@ func sendRequest(req *gemini.Request) error {
|
||||||
case gemini.StatusClassClientCertificateRequired:
|
case gemini.StatusClassClientCertificateRequired:
|
||||||
fmt.Println("Generating client certificate for", req.Hostname())
|
fmt.Println("Generating client certificate for", req.Hostname())
|
||||||
return nil // TODO: Generate and store client certificate
|
return nil // TODO: Generate and store client certificate
|
||||||
default:
|
|
||||||
return fmt.Errorf("Protocol error: Server sent an invalid response")
|
|
||||||
}
|
}
|
||||||
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
type trust int
|
type trust int
|
||||||
|
|
|
@ -10,7 +10,7 @@ const (
|
||||||
StatusInput = 10
|
StatusInput = 10
|
||||||
StatusSensitiveInput = 11
|
StatusSensitiveInput = 11
|
||||||
StatusSuccess = 20
|
StatusSuccess = 20
|
||||||
StatusRedirectTemporary = 30
|
StatusRedirect = 30
|
||||||
StatusRedirectPermanent = 31
|
StatusRedirectPermanent = 31
|
||||||
StatusTemporaryFailure = 40
|
StatusTemporaryFailure = 40
|
||||||
StatusServerUnavailable = 41
|
StatusServerUnavailable = 41
|
||||||
|
|
29
server.go
29
server.go
|
@ -175,6 +175,35 @@ type Handler interface {
|
||||||
Serve(*ResponseWriter, *Request)
|
Serve(*ResponseWriter, *Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotFoundHandler returns a simple handler that responds to each request with
|
||||||
|
// the status code NotFound.
|
||||||
|
func NotFound() Handler {
|
||||||
|
return HandlerFunc(func(rw *ResponseWriter, req *Request) {
|
||||||
|
rw.WriteHeader(StatusNotFound, "Not found")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect 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 Redirect(url string, permanent bool) Handler {
|
||||||
|
return HandlerFunc(func(rw *ResponseWriter, req *Request) {
|
||||||
|
if permanent {
|
||||||
|
rw.WriteHeader(StatusRedirectPermanent, url)
|
||||||
|
} else {
|
||||||
|
rw.WriteHeader(StatusRedirect, url)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input returns a simple handler that responds to each request with
|
||||||
|
// a request for input.
|
||||||
|
func Input(prompt string) Handler {
|
||||||
|
return HandlerFunc(func(rw *ResponseWriter, req *Request) {
|
||||||
|
rw.WriteHeader(StatusInput, prompt)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ServeMux is a Gemini request multiplexer.
|
// ServeMux is a Gemini request multiplexer.
|
||||||
// It matches the URL of each incoming request against a list of registered
|
// 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
|
// patterns and calls the handler for the pattern that most closesly matches
|
||||||
|
|
Loading…
Reference in New Issue
Block a user