Pull request: all: imp http handlers, imp docs
Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
This commit is contained in:
@@ -522,12 +522,12 @@ func (s *Server) handleDOH(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) registerHandlers() {
|
||||
s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig)
|
||||
s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig)
|
||||
s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS)
|
||||
s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig)
|
||||
s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig)
|
||||
s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS)
|
||||
|
||||
s.conf.HTTPRegister("GET", "/control/access/list", s.handleAccessList)
|
||||
s.conf.HTTPRegister("POST", "/control/access/set", s.handleAccessSet)
|
||||
s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList)
|
||||
s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet)
|
||||
|
||||
s.conf.HTTPRegister("", "/dns-query", s.handleDOH)
|
||||
}
|
||||
|
||||
@@ -369,8 +369,8 @@ func handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// RegisterAuthHandlers - register handlers
|
||||
func RegisterAuthHandlers() {
|
||||
Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin)))
|
||||
httpRegister("GET", "/control/logout", handleLogout)
|
||||
Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin)))
|
||||
httpRegister(http.MethodGet, "/control/logout", handleLogout)
|
||||
}
|
||||
|
||||
func parseCookie(cookie string) string {
|
||||
|
||||
@@ -119,7 +119,7 @@ func TestAuthHTTP(t *testing.T) {
|
||||
w.hdr = make(http.Header)
|
||||
r := http.Request{}
|
||||
r.Header = make(http.Header)
|
||||
r.Method = "GET"
|
||||
r.Method = http.MethodGet
|
||||
|
||||
// get / - we're redirected to login page
|
||||
r.URL = &url.URL{Path: "/"}
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestAuthGL(t *testing.T) {
|
||||
binary.BigEndian.PutUint32(data, tval)
|
||||
}
|
||||
assert.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644))
|
||||
r, _ := http.NewRequest("GET", "http://localhost/", nil)
|
||||
r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil)
|
||||
r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"})
|
||||
assert.True(t, glProcessCookie(r))
|
||||
GLMode = false
|
||||
|
||||
@@ -43,7 +43,7 @@ func addDNSAddress(dnsAddresses *[]string, addr string) {
|
||||
*dnsAddresses = append(*dnsAddresses, addr)
|
||||
}
|
||||
|
||||
func handleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
func handleStatus(w http.ResponseWriter, _ *http.Request) {
|
||||
c := dnsforward.FilteringConfig{}
|
||||
if Context.dnsServer != nil {
|
||||
Context.dnsServer.WriteDiskConfig(&c)
|
||||
@@ -140,7 +140,7 @@ func ensure(method string, handler func(http.ResponseWriter, *http.Request)) fun
|
||||
return
|
||||
}
|
||||
|
||||
if method == "POST" || method == "PUT" || method == "DELETE" {
|
||||
if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete {
|
||||
Context.controlLock.Lock()
|
||||
defer Context.controlLock.Unlock()
|
||||
}
|
||||
@@ -150,11 +150,11 @@ func ensure(method string, handler func(http.ResponseWriter, *http.Request)) fun
|
||||
}
|
||||
|
||||
func ensurePOST(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
|
||||
return ensure("POST", handler)
|
||||
return ensure(http.MethodPost, handler)
|
||||
}
|
||||
|
||||
func ensureGET(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
|
||||
return ensure("GET", handler)
|
||||
return ensure(http.MethodGet, handler)
|
||||
}
|
||||
|
||||
// Bridge between http.Handler object and Go function
|
||||
|
||||
Reference in New Issue
Block a user