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 {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/join", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != httpm.POST {
|
||||
http.Error(w, "Method must be POST", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
mux.HandleFunc("POST /join", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
decoder := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1024*1024))
|
||||
var jr joinRequest
|
||||
@ -146,11 +142,7 @@ func (c *Consensus) makeCommandMux() *http.ServeMux {
|
||||
return
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/executeCommand", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != httpm.POST {
|
||||
http.Error(w, "Bad Request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
mux.HandleFunc("POST /executeCommand", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
var cmd Command
|
||||
|
@ -47,10 +47,10 @@ func serveMonitor(c *Consensus, ts *tsnet.Server, listenAddr string) (*http.Serv
|
||||
}
|
||||
m := &monitor{con: c, ts: ts}
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/full", m.handleFullStatus)
|
||||
mux.HandleFunc("/", m.handleSummaryStatus)
|
||||
mux.HandleFunc("/netmap", m.handleNetmap)
|
||||
mux.HandleFunc("/dial", m.handleDial)
|
||||
mux.HandleFunc("GET /full", m.handleFullStatus)
|
||||
mux.HandleFunc("GET /{$}", m.handleSummaryStatus)
|
||||
mux.HandleFunc("GET /netmap", m.handleNetmap)
|
||||
mux.HandleFunc("POST /dial", m.handleDial)
|
||||
srv := &http.Server{Handler: mux}
|
||||
go func() {
|
||||
err := srv.Serve(ln)
|
||||
|
Loading…
x
Reference in New Issue
Block a user