5e20ac7ed5
Merge in DNS/adguard-home from beta-client-2 to master
Squashed commit of the following:
commit b2640cc49a6c5484d730b534dcf5a8013d7fa478
Merge: 659def862 aef4659e9
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 19:23:09 2020 +0300
Merge branch 'master' into beta-client-2
commit 659def8626467949c35b7a6a0c99ffafb07b4385
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 17:25:14 2020 +0300
all: upgrade github actions node version
commit b4b8cf8dd75672e9155da5d111ac66e8f5ba1535
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date: Tue Dec 29 16:57:14 2020 +0300
all: beta client squashed
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package home
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghio"
|
|
|
|
"github.com/AdguardTeam/golibs/log"
|
|
)
|
|
|
|
// middlerware is a wrapper function signature.
|
|
type middleware func(http.Handler) http.Handler
|
|
|
|
// withMiddlewares consequently wraps h with all the middlewares.
|
|
func withMiddlewares(h http.Handler, middlewares ...middleware) (wrapped http.Handler) {
|
|
wrapped = h
|
|
|
|
for _, mw := range middlewares {
|
|
wrapped = mw(wrapped)
|
|
}
|
|
|
|
return wrapped
|
|
}
|
|
|
|
// RequestBodySizeLimit is maximum request body length in bytes.
|
|
const RequestBodySizeLimit = 64 * 1024
|
|
|
|
// limitRequestBody wraps underlying handler h, making it's request's body Read
|
|
// method limited.
|
|
func limitRequestBody(h http.Handler) (limited http.Handler) {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var err error
|
|
r.Body, err = aghio.LimitReadCloser(r.Body, RequestBodySizeLimit)
|
|
if err != nil {
|
|
log.Error("limitRequestBody: %s", err)
|
|
|
|
return
|
|
}
|
|
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
// wrapIndexBeta returns handler that deals with new client.
|
|
func (web *Web) wrapIndexBeta(http.Handler) (wrapped http.Handler) {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
h, pattern := Context.mux.Handler(r)
|
|
switch pattern {
|
|
case "/":
|
|
web.handlerBeta.ServeHTTP(w, r)
|
|
case "/install.html":
|
|
web.installerBeta.ServeHTTP(w, r)
|
|
default:
|
|
h.ServeHTTP(w, r)
|
|
}
|
|
})
|
|
}
|