diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index a699b8f02..e3e7401e7 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -707,6 +707,9 @@ func (h *peerAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case "/v0/interfaces": h.handleServeInterfaces(w, r) return + case "/v0/doctor": + h.handleServeDoctor(w, r) + return case "/v0/ingress": metricIngressCalls.Add(1) h.handleServeIngress(w, r) @@ -818,6 +821,24 @@ func (h *peerAPIHandler) handleServeInterfaces(w http.ResponseWriter, r *http.Re fmt.Fprintln(w, "") } +func (h *peerAPIHandler) handleServeDoctor(w http.ResponseWriter, r *http.Request) { + if !h.canDebug() { + http.Error(w, "denied; no debug access", http.StatusForbidden) + return + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + fmt.Fprintln(w, "
") + + h.ps.b.Doctor(r.Context(), func(format string, args ...any) { + line := fmt.Sprintf(format, args) + fmt.Fprintln(w, html.EscapeString(line)) + }) + + fmt.Fprintln(w, "") +} + type incomingFile struct { name string // "foo.jpg" started time.Time