From f6311288683cd97e14f17e662ccf92f49b04595a Mon Sep 17 00:00:00 2001 From: Simeng He Date: Wed, 2 Jun 2021 13:54:13 -0400 Subject: [PATCH] Added basic handler placeholder and route in testcontrol Signed-off-by: Simeng He --- tstest/integration/testcontrol/testcontrol.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tstest/integration/testcontrol/testcontrol.go b/tstest/integration/testcontrol/testcontrol.go index 4683cbc0b..434b6a311 100644 --- a/tstest/integration/testcontrol/testcontrol.go +++ b/tstest/integration/testcontrol/testcontrol.go @@ -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()