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)
| 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. |
| 175 | func 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 | |
| 187 | func parseVariables(body []byte, vardefs []api.HTTPRequestResponseVariable, variables map[string]string) error { |
| 188 | for _, vardef := range vardefs { |