MCPcopy Index your code
hub / github.com/bootdotdev/bootdev / truncateAndStringifyBody

Function truncateAndStringifyBody

checks/http.go:175–185  ·  view source on GitHub ↗

Return a capped string representation of the response body. Text-like responses are allowed up to ~1 MiB, while likely-binary responses are capped more aggressively (~16 KiB) to avoid large payloads when serialized to JSON. We intentionally stringify raw bytes, even for binary data, so that ASCII

(body []byte)

Source from the content-addressed store, hash-verified

173// embedded in binary (e.g. "moov" in MP4 files) remain searchable by downstream checks.
174// The result is not guaranteed to be valid UTF-8 or lossless.
175func truncateAndStringifyBody(body []byte) string {
176 maxBodyLength := 1024 * 1024 // 1 MiB
177 if likelyBinary(body) {
178 maxBodyLength = 16 * 1024 // 16 KiB
179 }
180 if len(body) > maxBodyLength {
181 body = body[:maxBodyLength]
182 body = trimIncompleteUTF8(body)
183 }
184 return string(body)
185}
186
187func parseVariables(body []byte, vardefs []api.HTTPRequestResponseVariable, variables map[string]string) error {
188 for _, vardef := range vardefs {

Callers 2

runHTTPRequestFunction · 0.85

Calls 2

likelyBinaryFunction · 0.85
trimIncompleteUTF8Function · 0.85