* control: refactor: all handlers are registered via httpRegister()

* move some code to home/control_filtering.go
This commit is contained in:
Simon Zolin
2019-08-21 14:39:37 +03:00
parent e6bd2a101d
commit 452a668a5b
11 changed files with 301 additions and 348 deletions

View File

@@ -73,8 +73,6 @@ func ApplyBlockedServices(setts *dnsfilter.RequestFilteringSettings, list []stri
}
func handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL)
config.RLock()
list := config.DNS.BlockedServices
config.RUnlock()
@@ -88,8 +86,6 @@ func handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
}
func handleBlockedServicesSet(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL)
list := []string{}
err := json.NewDecoder(r.Body).Decode(&list)
if err != nil {
@@ -114,6 +110,6 @@ func handleBlockedServicesSet(w http.ResponseWriter, r *http.Request) {
// RegisterBlockedServicesHandlers - register HTTP handlers
func RegisterBlockedServicesHandlers() {
http.HandleFunc("/control/blocked_services/list", postInstall(optionalAuth(ensureGET(handleBlockedServicesList))))
http.HandleFunc("/control/blocked_services/set", postInstall(optionalAuth(ensurePOST(handleBlockedServicesSet))))
httpRegister(http.MethodGet, "/control/blocked_services/list", handleBlockedServicesList)
httpRegister(http.MethodPost, "/control/blocked_services/set", handleBlockedServicesSet)
}