fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

Reuse body for response

Open megashchik opened this issue 1 year ago • 3 comments
trafficstars

Greetings!

I have the following problem I have a fairly heavy query, the answer to which takes up a lot of space I would like to reuse the buffer for it This can be done via fasthttp.Post, but you cannot insert a complex request with headers there

It seems like the solution would be something like this

 req := fasthttp.AcquireRequest()
 resp := fasthttp.AcquireResponse()
 defer fasthttp.ReleaseRequest(req)
 defer fasthttp.ReleaseResponse(resp)
 // set headers
 resp.KeepBodyBuffer = true
 err = fasthttp.Do(req, resp)
 if err != nil {
   return err
 }
 resp.KeepBodyBuffer = false
 ...

However, the keepBodyBuffer field is private

megashchik avatar Jul 22 '24 10:07 megashchik

Why do you want to set keepBodyBuffer to true? Without it memory is also reused, just between different requests using a pool.

erikdubbelboer avatar Jul 23 '24 19:07 erikdubbelboer

Because I want to use the same big buffer for the response And after removing it, because such a call rarely works and I don't want a large buffer to end up in the pool I have a method call where I am asking for a large amount of data still in large chunks

megashchik avatar Jul 24 '24 11:07 megashchik

So you want to keep reusing the fasthttp.Response multiple times for this heavy call, without calling fasthttp.ReleaseResponse(resp)? Because you have other light calls that you don't want to get mixed up with this heavy call?

If that is the case I understand and I would be open to a pull request that makes KeepBodyBuffer public with some good documentation.

erikdubbelboer avatar Jul 28 '24 09:07 erikdubbelboer