Request/response body debugging for spent buffers

This commit is contained in:
2023-12-12 01:26:34 -06:00
parent 72d32d672e
commit 7240eaeea2

View File

@@ -22,17 +22,20 @@ func DebugRequest(req *http.Request) string {
if err != nil {
str += fmt.Sprintf("\n\n {error while reading request body buffer: %s}", err)
} else {
if len(body) == 0 {
str += fmt.Sprintf("\n\n{empty body}")
} else {
str += fmt.Sprintf("\n\n%s", body)
}
}
}
return str
}
func DebugResponse(res *http.Response) string {
str := fmt.Sprintf("[%s %s]", res.Status, res.Request.URL.String())
// Add all headers
for header_name, header_values := range res.Header {
for _, header_value := range header_values {
@@ -46,10 +49,14 @@ func DebugResponse(res *http.Response) string {
if err != nil {
str += fmt.Sprintf("\n\n {error while reading response body buffer: %s}", err)
} else {
if len(body) == 0 {
str += "\n\n{empty body}"
} else {
str += fmt.Sprintf("\n\n%s", body)
}
}
}
return str
}