bodyclose icon indicating copy to clipboard operation
bodyclose copied to clipboard

FP wrapping http body in MaxBytesReader

Open percivalalb opened this issue 1 year ago • 0 comments

https://pkg.go.dev/net/http#MaxBytesReader

closes the underlying reader when its Close method is called.

Is it possible to detect when the body could be implicitly closed like in the below::

res, err := client.Do(req)
if err != nil {
    panic(err)
}

resBody := res.Body

if maxMediaSize > 0 {
    resBody = http.MaxBytesReader(nil, res.Body, maxMediaSize)
}

defer resBody.Close()

percivalalb avatar Nov 15 '24 14:11 percivalalb