BodyUncompressedWithLimit returns body data and if needed decompresses it from gzip, deflate, brotli or zstd. The size of uncompressed data is limited to maxBodySize bytes. If maxBodySize <= 0, then no limit is applied.
(maxBodySize int)
| 701 | // |
| 702 | // If maxBodySize <= 0, then no limit is applied. |
| 703 | func (resp *Response) BodyUncompressedWithLimit(maxBodySize int) ([]byte, error) { |
| 704 | switch string(resp.Header.ContentEncoding()) { |
| 705 | case "": |
| 706 | return resp.Body(), nil |
| 707 | case "deflate": |
| 708 | return resp.BodyInflateWithLimit(maxBodySize) |
| 709 | case "gzip": |
| 710 | return resp.BodyGunzipWithLimit(maxBodySize) |
| 711 | case "br": |
| 712 | return resp.BodyUnbrotliWithLimit(maxBodySize) |
| 713 | case "zstd": |
| 714 | return resp.BodyUnzstdWithLimit(maxBodySize) |
| 715 | default: |
| 716 | return nil, ErrContentEncodingUnsupported |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | // BodyWriteTo writes request body to w. |
| 721 | func (req *Request) BodyWriteTo(w io.Writer) error { |