From 8054d68f7949e11132cb4bd12a2638d7589c5ccd Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 10 Sep 2024 18:49:25 +0200 Subject: [PATCH] feat(rate): add customizable X-Powered-By header --- rate/handler.go | 5 +++++ rate/proxy-config.example.json | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rate/handler.go b/rate/handler.go index 5cbfff3..7ab0b59 100644 --- a/rate/handler.go +++ b/rate/handler.go @@ -25,6 +25,7 @@ type Handler struct { Port int `json:"port"` ProxyTarget string `json:"proxy_target"` Debug bool `json:"debug"` + PoweredBy string `json:"powered_by"` limiter *Limiter proxy *httputil.ReverseProxy @@ -32,6 +33,10 @@ type Handler struct { } func (hn *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if hn.PoweredBy != "" { + w.Header().Set("X-Powered-By", hn.PoweredBy) + } + // all public api endpoints are prefixed with this if !strings.HasPrefix(r.URL.Path, "/api/v2") { w.WriteHeader(http.StatusNotFound) diff --git a/rate/proxy-config.example.json b/rate/proxy-config.example.json index 1d2d6af..427acef 100644 --- a/rate/proxy-config.example.json +++ b/rate/proxy-config.example.json @@ -1,5 +1,6 @@ { "port": 5003, "proxy_target": "http://localhost:5000", - "debug": true + "debug": true, + "powered_by": "5 gay rats" }