+ http server: enable gzip compression for /control/querylog
This commit is contained in:
parent
cca61a33c6
commit
3f404bc37e
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/golibs/utils"
|
"github.com/AdguardTeam/golibs/utils"
|
||||||
|
"github.com/NYTimes/gziphandler"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
govalidator "gopkg.in/asaskevich/govalidator.v4"
|
govalidator "gopkg.in/asaskevich/govalidator.v4"
|
||||||
)
|
)
|
||||||
@ -1100,7 +1101,7 @@ func registerControlHandlers() {
|
|||||||
http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus))))
|
http.HandleFunc("/control/status", postInstall(optionalAuth(ensureGET(handleStatus))))
|
||||||
http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable))))
|
http.HandleFunc("/control/enable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionEnable))))
|
||||||
http.HandleFunc("/control/disable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionDisable))))
|
http.HandleFunc("/control/disable_protection", postInstall(optionalAuth(ensurePOST(handleProtectionDisable))))
|
||||||
http.HandleFunc("/control/querylog", postInstall(optionalAuth(ensureGET(handleQueryLog))))
|
http.Handle("/control/querylog", postInstallHandler(optionalAuthHandler(gziphandler.GzipHandler(ensureGETHandler(handleQueryLog)))))
|
||||||
http.HandleFunc("/control/querylog_enable", postInstall(optionalAuth(ensurePOST(handleQueryLogEnable))))
|
http.HandleFunc("/control/querylog_enable", postInstall(optionalAuth(ensurePOST(handleQueryLogEnable))))
|
||||||
http.HandleFunc("/control/querylog_disable", postInstall(optionalAuth(ensurePOST(handleQueryLogDisable))))
|
http.HandleFunc("/control/querylog_disable", postInstall(optionalAuth(ensurePOST(handleQueryLogDisable))))
|
||||||
http.HandleFunc("/control/set_upstreams_config", postInstall(optionalAuth(ensurePOST(handleSetUpstreamConfig))))
|
http.HandleFunc("/control/set_upstreams_config", postInstall(optionalAuth(ensurePOST(handleSetUpstreamConfig))))
|
||||||
|
15
helpers.go
15
helpers.go
@ -45,6 +45,21 @@ func ensureGET(handler func(http.ResponseWriter, *http.Request)) func(http.Respo
|
|||||||
return ensure("GET", handler)
|
return ensure("GET", handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bridge between http.Handler object and Go function
|
||||||
|
type httpHandler struct {
|
||||||
|
handler func(http.ResponseWriter, *http.Request)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
h.handler(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ensureGETHandler(handler func(http.ResponseWriter, *http.Request)) http.Handler {
|
||||||
|
h := httpHandler{}
|
||||||
|
h.handler = ensure("GET", handler)
|
||||||
|
return &h
|
||||||
|
}
|
||||||
|
|
||||||
func ensurePUT(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
|
func ensurePUT(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
|
||||||
return ensure("PUT", handler)
|
return ensure("PUT", handler)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user