Pull request 2693: AGDNS-4202-use-golibs-mw
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled

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 2026-07-06 15:31:34 +00:00
parent cf15e1759a
commit 315648f942
2 changed files with 6 additions and 18 deletions

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

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)