Skip to content

Allow user-provided buffer we write responses into directly #936

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

Closed
quinnj opened this issue Oct 13, 2022 · 1 comment
Closed

Allow user-provided buffer we write responses into directly #936

quinnj opened this issue Oct 13, 2022 · 1 comment
Assignees

Comments

@quinnj
Copy link
Member

quinnj commented Oct 13, 2022

For efficiency and to avoid allocations, I may want the ability to pre-allocate buffers and provide them to HTTP.request to be used directly when writing a response.

I'm not exactly sure the best interface for this, but we already have response_stream where the user can provide an IO that we write the response body to. So one option might be that the user can just provide an AbstractVector{UInt8} to response_stream and then we either use that directly or wrap it in some internal wrapper struct that is handled specially when writing.

One piece I haven't quite thought through either is what to do about the size of the buffer vs. size of the response body. What if the user-provided buffer is too small? or too big? do we somehow signal this and what is the best way to do that?

Also as an overall thought, it would be ideal if we could get to a scenario where HTTP.request can potentially avoid any allocations at all, but I'm not quite sure what all the current allocations involve, so I'm not sure how feasible this actually is; just something to think about.

@quinnj
Copy link
Member Author

quinnj commented Jan 12, 2023

This is now supported by passing an exactly right-size Vector{UInt8} as the response_stream arg, or an IOBuffer as the response_stream (which can wrap a pre-allocated Vector{UInt8}) and the IOBuffer will be grown (if write is allowed) and the # of bytes will be recorded by the IOBuffer if the Vector{UInt8} isn't fully used.

@quinnj quinnj closed this as completed Jan 12, 2023
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