aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradnano <[email protected]>2020-09-28 16:07:51 -0400
committeradnano <[email protected]>2020-09-28 16:07:51 -0400
commit4c0b13fb576042fb4831cd964afbe1f21fb16d31 (patch)
treef5250aba4e47e9f767b967c48f41fa34f90de243
parentRemove support for matching schemes (diff)
downloadgo-gemini-4c0b13fb576042fb4831cd964afbe1f21fb16d31.tar.xz
go-gemini-4c0b13fb576042fb4831cd964afbe1f21fb16d31.zip
Refuse requests for non-gemini schemes
-rw-r--r--examples/auth/auth.go2
-rw-r--r--server.go5
2 files changed, 6 insertions, 1 deletions
diff --git a/examples/auth/auth.go b/examples/auth/auth.go
index 94b3016..bcf7bf1 100644
--- a/examples/auth/auth.go
+++ b/examples/auth/auth.go
@@ -79,7 +79,7 @@ func login(rw *gmi.ResponseWriter, req *gmi.Request) {
sessions[fingerprint] = &session{
username: username,
}
- gmi.Redirect(rw, req, "/login/password")
+ gmi.Redirect(rw, req, "/login#password")
})
})
}
diff --git a/server.go b/server.go
index cea6f64..158f9cf 100644
--- a/server.go
+++ b/server.go
@@ -579,6 +579,11 @@ func (mux *ServeMux) shouldRedirectRLocked(host, path string) bool {
// If there is no registered handler that applies to the request,
// Handler returns a ``page not found'' handler and an empty pattern.
func (mux *ServeMux) Handler(r *Request) (h Handler, pattern string) {
+ // Refuse requests for non-gemini schemes.
+ if r.URL.Scheme != "gemini" {
+ return NotFoundHandler(), ""
+ }
+
// All other requests have any port stripped and path cleaned
// before passing to mux.handler.
host := stripHostPort(r.Host)