Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
792 B · 28 lines
Go
1234567891011121314151617181920212223242526272829package discord
import ( "io" "strings" "unicode")
// maxResponseBodyLogBytes caps how much of an external webhook response body// we read for logging and error messages. Webhook endpoints are// user-configured, so their bodies are untrusted input.const maxResponseBodyLogBytes = 1024
// readResponseBody reads a bounded, log-safe rendering of an external webhook// response body: truncated to maxResponseBodyLogBytes with control characters// stripped so external content can't disrupt log parsing.func readResponseBody(r io.Reader) (string, error) { body, err := io.ReadAll(io.LimitReader(r, maxResponseBodyLogBytes)) if err != nil { return "", err } return strings.Map(func(r rune) rune { if unicode.IsControl(r) { return -1 } return r }, string(body)), nil}