Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse body for response #1811

Open
megashchik opened this issue Jul 22, 2024 · 3 comments
Open

Reuse body for response #1811

megashchik opened this issue Jul 22, 2024 · 3 comments

Comments

@megashchik
Copy link

megashchik commented Jul 22, 2024

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 megashchik changed the title reuse body for response Reuse body for response Jul 22, 2024
@erikdubbelboer
Copy link
Collaborator

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

@megashchik
Copy link
Author

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

@erikdubbelboer
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants