From 05202099f771008bde09dbc705536935482dfeb3 Mon Sep 17 00:00:00 2001 From: Florian Preinstorfer Date: Sat, 15 Mar 2025 13:57:25 +0100 Subject: [PATCH] Set content-type to JSON for some debug endpoints Some endpoints in /debug send JSON data as string. Set the Content-Type header to "application/json" which renders nicely in Firefox. Mention the /debug route in the example configuration. --- config-example.yaml | 6 ++---- hscontrol/debug.go | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/config-example.yaml b/config-example.yaml index f6e043c6..50fd1edd 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -18,10 +18,8 @@ server_url: http://127.0.0.1:8080 # listen_addr: 0.0.0.0:8080 listen_addr: 127.0.0.1:8080 -# Address to listen to /metrics, you may want -# to keep this endpoint private to your internal -# network -# +# Address to listen to /metrics and /debug, you may want +# to keep this endpoint private to your internal network metrics_listen_addr: 127.0.0.1:9090 # Address to listen for gRPC. diff --git a/hscontrol/debug.go b/hscontrol/debug.go index 0d20ddf9..2b245b58 100644 --- a/hscontrol/debug.go +++ b/hscontrol/debug.go @@ -25,7 +25,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(config) })) @@ -35,7 +35,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(pol) })) @@ -47,7 +47,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(filterJSON) })) @@ -74,7 +74,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(sshJSON) })) @@ -86,7 +86,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(dmJSON) })) @@ -96,7 +96,7 @@ func (h *Headscale) debugHTTPServer() *http.Server { httpError(w, err) return } - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(registrationsJSON) }))