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

Way to upload body from non-static &[u8]? #75

vmalloc opened this issue Sep 10, 2019 · 2 comments


Copy link

commented Sep 10, 2019

The way I currently understand it, Body needs to be constructed from either an owned vector or a 'static construct. Assuming I'm making a synchronous call in the same thread, I believe it makes sense to allow a non-static reader or &[u8] to reduce memory footprint in case of retries or big uploads. Is there a way to do this at the moment?

@sagebind sagebind added the question label Sep 12, 2019


This comment has been minimized.

Copy link

commented Sep 12, 2019

There's not currently a way to use a borrowed buffer, no. Even if you make a synchoronous call in a single thread, the body is still moved to a (single) background thread to be sent. This is what allows a single client to multiplex a large number of simultaneous requests.

Theoretically, it would be safe to use a borrowed buffer as the request body, as long as the reference is Send and Sync, and we require the lifetime to live at least as long as the start of the method call until the response headers are received, though this may complicate the API a little bit. I'll have to think about this one.

Generally, it is common in networking to use the bytes crate to reduce buffer copies without adding too many restrictions. In Isahc you can convert a Bytes into a Body without any copies.

Hope that helps.


This comment has been minimized.

Copy link

commented Sep 12, 2019

@sagebind Thanks a lot for the info! I was vaguely aware of bytes but didn't make the connection that it would help here. I'll look into that! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.