HTTP.jl icon indicating copy to clipboard operation
HTTP.jl copied to clipboard

Allow user-provided buffer we write responses into directly

Open quinnj opened this issue 3 years ago • 0 comments

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 avatar Oct 13 '22 15:10 quinnj