Skip to content

Commit

Permalink
feat: add new RequireInputHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h authored Aug 9, 2021
2 parents 69de561 + 4bd6213 commit fb6d06a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ func RequireCertificateHandler(h Handler, authoriser func(certID, certKey string
})
}

// RequireInputHandler returns a handler that enforces all incoming requests have a populated
// querystring.
// `prompt` is returned as response META if input is not provided.
func RequireInputHandler(h Handler, prompt string) Handler {
return HandlerFunc(func(w ResponseWriter, r *Request) {
if r.URL.RawQuery == "" {
w.SetHeader(CodeInput, prompt)
return
}
h.ServeGemini(w, r)
})
}

// AuthoriserAllowAll allows any authenticated user to access the handler.
func AuthoriserAllowAll(id, key string) bool {
return true
Expand Down

0 comments on commit fb6d06a

Please sign in to comment.