Skip to content

Commit

Permalink
Add RequireInputHandler
Browse files Browse the repository at this point in the history
This handler wrapper allows users to easily create flexible input-required endpoints
using custom prompts.
  • Loading branch information
aThorp96 committed Aug 3, 2021
1 parent 69de561 commit 4bd6213
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 4bd6213

Please sign in to comment.