ServeHTTP implements http.Handler.
(w http.ResponseWriter, r *http.Request)
| 74 | |
| 75 | // ServeHTTP implements http.Handler. |
| 76 | func (d *DebugHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 77 | if !AllowDebugAccess(r) { |
| 78 | http.Error(w, "debug access denied", http.StatusForbidden) |
| 79 | return |
| 80 | } |
| 81 | if r.URL.Path != "/debug/" { |
| 82 | // Sub-handlers are handled by the parent mux directly. |
| 83 | http.NotFound(w, r) |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | AddBrowserHeaders(w) |
| 88 | f := func(format string, args ...any) { fmt.Fprintf(w, format, args...) } |
| 89 | f("<html><body><h1>%s</h1><ul>", html.EscapeString(d.title)) |
| 90 | for _, kv := range d.kvs { |
| 91 | kv(w) |
| 92 | } |
| 93 | for _, url := range d.urls { |
| 94 | io.WriteString(w, url) |
| 95 | } |
| 96 | for _, section := range d.sections { |
| 97 | section(w, r) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | func (d *DebugHandler) handle(slug string, handler http.Handler) string { |
| 102 | href := "/debug/" + slug |
no test coverage detected