Added basic handler placeholder and route in testcontrol

Signed-off-by: Simeng He <simeng@tailscale.com>
This commit is contained in:
Simeng He 2021-06-02 13:54:13 -04:00
parent a321c24667
commit f631128868

View File

@ -99,6 +99,7 @@ func (s *Server) initMux() {
s.mux.HandleFunc("/", s.serveUnhandled)
s.mux.HandleFunc("/key", s.serveKey)
s.mux.HandleFunc("/machine/", s.serveMachine)
s.mux.HandleFunc("/ping", s.servePingInfo)
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -172,6 +173,19 @@ func (s *Server) serveMachine(w http.ResponseWriter, r *http.Request) {
}
}
// servePingInfo currently placeholder, determine the correct response to client
func (s *Server) servePingInfo(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
if r.Method != "PUT" {
http.Error(w, "Only PUT requests are supported currently", http.StatusMethodNotAllowed)
}
_, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
http.Error(w, "Failed to read request body", http.StatusInternalServerError)
}
}
// Node returns the node for nodeKey. It's always nil or cloned memory.
func (s *Server) Node(nodeKey tailcfg.NodeKey) *tailcfg.Node {
s.mu.Lock()