mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-29 02:18:51 +03:00
681c604c22
Merge in DNS/adguard-home from nextapi-frontend-fs to master
Squashed commit of the following:
commit 3ed959f21939cf5590c27426af46906cbffed502
Merge: e60bbdd04 9fda7bfd3
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Jun 13 13:37:00 2023 +0300
Merge branch 'master' into nextapi-frontend-fs
commit e60bbdd04ce841c1aaaa198cc9dc85ae14799ffa
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Jun 9 14:53:09 2023 +0300
next: support frontend fs
38 lines
897 B
Go
38 lines
897 B
Go
package websvc
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
|
"github.com/AdguardTeam/golibs/httphdr"
|
|
"github.com/AdguardTeam/golibs/log"
|
|
)
|
|
|
|
// Middlewares
|
|
|
|
// jsonMw sets the content type of the response to application/json.
|
|
func jsonMw(h http.Handler) (wrapped http.HandlerFunc) {
|
|
f := func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set(httphdr.ContentType, aghhttp.HdrValApplicationJSON)
|
|
|
|
h.ServeHTTP(w, r)
|
|
}
|
|
|
|
return http.HandlerFunc(f)
|
|
}
|
|
|
|
// logMw logs the queries with level debug.
|
|
func logMw(h http.Handler) (wrapped http.HandlerFunc) {
|
|
f := func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
m, u := r.Method, r.RequestURI
|
|
|
|
log.Debug("websvc: %s %s started", m, u)
|
|
defer func() { log.Debug("websvc: %s %s finished in %s", m, u, time.Since(start)) }()
|
|
|
|
h.ServeHTTP(w, r)
|
|
}
|
|
|
|
return http.HandlerFunc(f)
|
|
}
|