xmlDecodeAndBody reads the whole body up to 1MB and tries to XML decode it into v. The body that was read and any error from reading or decoding is returned.
(bodyReader io.Reader, v interface{})
| 85 | // tries to XML decode it into v. |
| 86 | // The body that was read and any error from reading or decoding is returned. |
| 87 | func xmlDecodeAndBody(bodyReader io.Reader, v interface{}) ([]byte, error) { |
| 88 | // read the whole body (up to 1MB) |
| 89 | const maxBodyLength = 1 << 20 |
| 90 | body, err := io.ReadAll(io.LimitReader(bodyReader, maxBodyLength)) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | return bytes.TrimSpace(body), xmlDecoder(bytes.NewReader(body), v) |
| 95 | } |
no test coverage detected