resty
resty copied to clipboard
Bypass copying the request body when it is too large
As of now the request body is by default read and copied to an in memory buffer. This behaviour increases the memory footprint in case we are uploading large data. Targeting use cases specific to passing large data in request body. Ideally, in case of large data we want to rely on http1.1 chunking or http2 streaming, for that we need to bypass reading the data in memory for efficiency.
This copying happens at two places in request middlewares(in sequence) -
- https://github.com/go-resty/resty/blob/master/middleware.go#L445
- https://github.com/go-resty/resty/blob/master/middleware.go#L208
Possible solution -
- We can assume that for large data the request body will be an
io.Readerand change code paths accordingly. We can introduce a flagnotCopyRequestBodysimilar tonotParseResponse
This issue is similar to - https://github.com/go-resty/resty/issues/495
Think this is the same problem: https://github.com/go-resty/resty/issues/309
It is similar, more towards the request body. But the idea is to not buffer data in memory.
Recently try to read chunk-based data from a 3-party API, but need to fall back to using the standard net/http Looking forward to seeing resty support this feature.