Pull request 2693: AGDNS-4202-use-golibs-mw

Squashed commit of the following:

commit 513b2c70fc2a1240090e35f7463cbad374c7394d
Merge: 65c86fddb cf15e1759
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date:   Mon Jul 6 18:24:13 2026 +0300

    Merge branch 'master' into AGDNS-4202-use-golibs-mw

commit 65c86fddba91ac7687bf1d94372f109c0e0c008a
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date:   Mon Jul 6 12:58:04 2026 +0300

    home: use middleware helpers from golibs;
This commit is contained in:
Maksim Kazantsev committed 2026-07-06 15:31:34 +00:00
1 parent cf15e1759a
commit 315648f942
2 files changed
+6 -18

No files matched your search

-16
View File
@@ -8,22 +8,6 @@ import (
"github.com/c2h5oh/datasize"
)
// middlerware is a wrapper function signature.
type middleware func(http.Handler) http.Handler
// withMiddlewares consequently wraps h with all the middlewares.
//
// TODO(e.burkov): Use [httputil.Wrap].
func withMiddlewares(h http.Handler, middlewares ...middleware) (wrapped http.Handler) {
wrapped = h
for _, mw := range middlewares {
wrapped = mw(wrapped)
}
return wrapped
}
const (
// defaultReqBodySzLim is the default maximum request body size.
defaultReqBodySzLim datasize.ByteSize = 64 * datasize.KB
+6 -2
View File
@@ -192,7 +192,11 @@ func newWebAPI(ctx context.Context, conf *webAPIConfig) (w *webAPI) {
mux := conf.mux
// if not configured, redirect / to /install.html, otherwise redirect /install.html to /
mux.Handle("/", withMiddlewares(clientFS, gziphandler.GzipHandler, w.postInstallHandler))
mux.Handle("/", httputil.Wrap(
clientFS,
httputil.MiddlewareFunc(w.postInstallHandler),
httputil.MiddlewareFunc(gziphandler.GzipHandler),
))
// add handlers for /install paths, we only need them when we're not configured yet
if conf.firstRun {
@@ -305,7 +309,7 @@ func (web *webAPI) start(ctx context.Context) {
// wrapMux wraps mux with common middlewares. l must not be nil.
func (web *webAPI) wrapMux(l *slog.Logger) (h http.Handler) {
h = withMiddlewares(web.conf.mux, limitRequestBody)
h = httputil.Wrap(web.conf.mux, httputil.MiddlewareFunc(limitRequestBody))
// TODO(a.garipov): Remove other logs like this in other code.
logMw := httputil.NewLogMiddleware(l, slog.LevelDebug)