go-resty / resty

Simple HTTP and REST client library for Go
MIT License
9.98k stars 706 forks source link

The SetContentLength(boo) method may cause an out-of-memory issue when uploading large files, such as 5GB. #755

Closed mail2fish closed 7 months ago

mail2fish commented 10 months ago

The SetContentLength method reads the entire content of the request body reader into memory to calculate the content length. This can potentially cause an out-of-memory issue. Setting the Content-Length header manually also seems ineffective. Is there any solution to this problem?

The issue is occurring in version 2.10.

jeevatkm commented 7 months ago

@mail2fish Resty reads the entire request info/fields to create an HTTP request. The out-of-memory issue is that your machine may need to have appropriate memory.

Possibly, you could try to set file size manually using os.Stat("/path/to/file") without opening a file.

In the v3, there are plans to optimize the flow.