middleware: health-check respond to all methods

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2019-09-19 16:05:07 -07:00
parent 490d131070
commit 5842f3033a
No known key found for this signature in database
GPG key ID: AEE4CF12FE86D07E
3 changed files with 34 additions and 20 deletions

View file

@ -149,11 +149,17 @@ func Healthcheck(endpoint, msg string) func(http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "middleware.Healthcheck")
defer span.End()
if r.Method == "GET" && strings.EqualFold(r.URL.Path, endpoint) {
if strings.EqualFold(r.URL.Path, endpoint) {
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(msg))
if r.Method == http.MethodGet {
w.Write([]byte(msg))
}
return
}
next.ServeHTTP(w, r.WithContext(ctx))