From bddb144f60fcf5ce6f4860cf977a287a0a7fc85b Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 26 Nov 2023 17:10:16 -0600 Subject: [PATCH] fix order of middlewares to handle limiting by IP after match handler sets ctx --- .gitignore | 1 + app/proxy/proxy.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 83f02e1..9df165e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ docker-compose-private.yml .vscode .idea *.gpg +reproxy-private.yml diff --git a/app/proxy/proxy.go b/app/proxy/proxy.go index 24d6ed7..b3af185 100644 --- a/app/proxy/proxy.go +++ b/app/proxy/proxy.go @@ -121,19 +121,19 @@ func (h *Http) Run(ctx context.Context) error { }() handler := R.Wrap(h.proxyHandler(), - R.Recoverer(log.Default()), // recover on errors - signatureHandler(h.Signature, h.Version), // send app signature - h.OnlyFrom.Handler, // limit source (remote) IPs if defined - h.pingHandler, // respond to /ping + R.Recoverer(log.Default()), // recover on errors + signatureHandler(h.Signature, h.Version), // send app signature + h.pingHandler, // respond to /ping basicAuthHandler(h.BasicAuthEnabled, h.BasicAuthAllowed), // basic auth - h.healthMiddleware, // respond to /health - h.matchHandler, // set matched routes to context - limiterSystemHandler(h.ThrottleSystem), // limit total requests/sec - limiterUserHandler(h.ThrottleUser), // req/seq per user/route match - h.mgmtHandler(), // handles /metrics and /routes for prometheus - h.pluginHandler(), // prc to external plugins - headersHandler(h.ProxyHeaders, h.DropHeader), // add response headers and delete some request headers - accessLogHandler(h.AccessLog), // apache-format log file + h.healthMiddleware, // respond to /health + h.matchHandler, // set matched routes to context + h.OnlyFrom.Handler, // limit source (remote) IPs if defined + limiterSystemHandler(h.ThrottleSystem), // limit total requests/sec + limiterUserHandler(h.ThrottleUser), // req/seq per user/route match + h.mgmtHandler(), // handles /metrics and /routes for prometheus + h.pluginHandler(), // prc to external plugins + headersHandler(h.ProxyHeaders, h.DropHeader), // add response headers and delete some request headers + accessLogHandler(h.AccessLog), // apache-format log file stdoutLogHandler(h.StdOutEnabled, logger.New(logger.Log(log.Default()), logger.Prefix("[INFO]")).Handler), maxReqSizeHandler(h.MaxBodySize), // limit request max size gzipHandler(h.GzEnabled), // gzip response