print body of selected HTTP responses when log level is debug (#5859)

This commit is contained in:
Alessandro Ros
2026-06-11 00:53:52 +02:00
committed by GitHub
parent 959f58cee9
commit d0cf294637
2 changed files with 14 additions and 4 deletions
+14 -2
View File
@@ -39,6 +39,7 @@ func dumpRequestLimited(r *http.Request) ([]byte, error) {
type responseRecorder struct {
w http.ResponseWriter
status int
body []byte
size int
}
@@ -50,7 +51,14 @@ func (w *responseRecorder) Write(b []byte) (int, error) {
if w.status == 0 {
w.status = http.StatusOK
}
w.size += len(b)
contentType := w.Header().Get("Content-Type")
if contentType == "application/sdp" || contentType == "application/trickle-ice-sdpfrag" {
w.body = append(w.body, b...)
} else {
w.size += len(b)
}
return w.w.Write(b)
}
@@ -64,9 +72,13 @@ func (w *responseRecorder) dump() string {
fmt.Fprintf(&buf, "%s %d %s\n", "HTTP/1.1", w.status, http.StatusText(w.status))
w.w.Header().Write(&buf) //nolint:errcheck
buf.Write([]byte("\n"))
if w.size > 0 {
if w.body != nil {
buf.Write(w.body)
} else if w.size > 0 {
fmt.Fprintf(&buf, "(body of %d bytes)", w.size)
}
return buf.String()
}
-2
View File
@@ -247,8 +247,6 @@ func (s *httpServer) onWHIPPost(ctx *gin.Context, pathName string, publish bool)
ctx.Header("Location", sessionLocation(publish, pathName, ctx.Request.URL.RawQuery, res.sx.secret))
ctx.Writer.WriteHeader(http.StatusCreated)
ctx.Writer.Write(res2.answer)
res.sx.Log(logger.Debug, "SDP answer:\n"+string(res2.answer))
}
func (s *httpServer) onWHIPPatch(ctx *gin.Context, rawSecret string) {