mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-01 21:21:04 +00:00
use mux patterns to check method
This commit is contained in:
parent
a0c39ea016
commit
80d3119965
@ -113,11 +113,7 @@ func (h authedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (c *Consensus) makeCommandMux() *http.ServeMux {
|
func (c *Consensus) makeCommandMux() *http.ServeMux {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/join", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("POST /join", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != httpm.POST {
|
|
||||||
http.Error(w, "Method must be POST", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
decoder := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1024*1024))
|
decoder := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1024*1024))
|
||||||
var jr joinRequest
|
var jr joinRequest
|
||||||
@ -146,11 +142,7 @@ func (c *Consensus) makeCommandMux() *http.ServeMux {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/executeCommand", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("POST /executeCommand", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != httpm.POST {
|
|
||||||
http.Error(w, "Bad Request", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
var cmd Command
|
var cmd Command
|
||||||
|
@ -47,10 +47,10 @@ func serveMonitor(c *Consensus, ts *tsnet.Server, listenAddr string) (*http.Serv
|
|||||||
}
|
}
|
||||||
m := &monitor{con: c, ts: ts}
|
m := &monitor{con: c, ts: ts}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/full", m.handleFullStatus)
|
mux.HandleFunc("GET /full", m.handleFullStatus)
|
||||||
mux.HandleFunc("/", m.handleSummaryStatus)
|
mux.HandleFunc("GET /{$}", m.handleSummaryStatus)
|
||||||
mux.HandleFunc("/netmap", m.handleNetmap)
|
mux.HandleFunc("GET /netmap", m.handleNetmap)
|
||||||
mux.HandleFunc("/dial", m.handleDial)
|
mux.HandleFunc("POST /dial", m.handleDial)
|
||||||
srv := &http.Server{Handler: mux}
|
srv := &http.Server{Handler: mux}
|
||||||
go func() {
|
go func() {
|
||||||
err := srv.Serve(ln)
|
err := srv.Serve(ln)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user