mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-01 15:55:49 +03:00
change both /health and /ping to exact url match
needed to prevent conflict with proxied services implementing /health or /ping
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
func (h *Http) healthMiddleware(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" && strings.HasSuffix(strings.ToLower(r.URL.Path), "/health") {
|
||||
if r.Method == "GET" && strings.ToLower(r.URL.Path) == "/health" {
|
||||
h.healthHandler(w, r)
|
||||
return
|
||||
}
|
||||
@@ -89,3 +89,18 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
log.Printf("[WARN] failed to send halth, %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// pingHandler middleware response with pong to /ping. Stops chain if ping request detected
|
||||
func (h *Http) pingHandler(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.Method == "GET" && strings.ToLower(r.URL.Path) == "/ping" {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("pong"))
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func (h *Http) Run(ctx context.Context) error {
|
||||
handler := R.Wrap(h.proxyHandler(),
|
||||
R.Recoverer(log.Default()),
|
||||
h.signatureHandler(),
|
||||
R.Ping,
|
||||
h.pingHandler,
|
||||
h.healthMiddleware,
|
||||
h.accessLogHandler(h.AccessLog),
|
||||
R.SizeLimit(h.MaxBodySize),
|
||||
|
||||
Reference in New Issue
Block a user