-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
non-Buf
body chunks
#3026
Comments
I did read and think about this when you wrote it up, but otherwise have not been able to make any progress. I was hopeful some other motivated individual would want to push on it before we hit 1.0, but seems not. I don't think that means this can't happen. Rather, I do think this can be added later. It might be a little but trickier, but I suspect doable with some cleverness. So, I'll leave this up as a desirable feature, but more discussion and proposal is needed (thus still |
Thanks. I appreciate the explicit consideration, and I hope you're right that it can be added later without an API break. |
I’d be interested in being able to serve static files with hyper but using the |
Is your feature request related to a problem? Please describe.
I'd like hyper to be able to support more advanced/efficient IO operations that don't use an intermediary
&[u8]
:sendfile(2)
,splice(2)
,copy_file_range(2)
,IO_URING_OP_SPLICE
, chains of io_uring read and write operations, etc.)mmap
->write
than the status quo (but see caveat below):write
/writev
/IO_URING_WRITEV
. (My server does this now, but it'd be nice to avoid the copy.)(One might point out that a userspace TLS implementation needs the bytes in userspace anyway. But at least on Linux, kTLS is possible, and there's been recent movement on using it from Rust: rustls/rustls#198. And sometimes people don't use TLS or handle it in an external proxy server.)
My half-baked trait below might have another benefit of allow a caller-supplied IO to control memory allocation more by providing chunks from a pool or something rather than fresh allocations done within hyper.
In terms of hyper's vision, I think this aligns with Fast and Flexible.
This has been in the back of my mind for a while, but the hyper v1.0.0-rc.1 post yesterday made me realize the clock might be ticking. The vision doc says "If it is determined necessary to make breaking changes to the API, we'll save them for after the 3 years." I fear this needs a breaking API change, and I'd be sad to miss the boat if it'll be that long before the next one.
If you consider API changes to support this to be too complex to maintain or that they'd introduce too much work/delay to design/implement before reaching hyper 1.0, that's one thing, but I'd rather at least bring it up first!
Describe the solution you'd like
My thought is that
hyper::body::Body::Data
needs to provide:Buf
is one such contract, but it's not suitable when you want to defer the actual read because it promises that the bytes can be produced immediately (not async) and infallibly.and then some users will use a chunk type that allows them to splice from one file descriptor straight to the output file descriptor, encrypting with kTLS. And an IO to match it.
The current IO bounds of
I: AsyncRead + AsyncWrite + Unpin
for theio
passed to e.g.hyper::server::conn::http2::Builder::serve_connection
can still be provided, but the advanced users will also want hyper to use some way of sending/receiving chunks without going through those traits. Half-baked sketch:(For
Chunk = Bytes
,poll_write_chunk
andpoll_read_chunk
should be implementable in terms ofpoll_write
andpoll_read
, respectively.)Lots I don't know:
There might be a lot to consider in those
...
bytes above: hyper at least needs a way to tell it the max bytes it's expecting in the next chunk based on framing.The proto layers need to plumb that through. Maybe this can be done without breaking compatibility with the existing API via default trait bounds and a "simple" methods that require
Data: Buf
and providepoll_write_chunk
andpoll_read_chunk
in terms ofpoll_write
andpoll_read
vs an "extended" methods that don't. Maybe it can't. I'm not sure!I see the
hyper::body::Incoming
interface usesData = Bytes
. It'd be nice to support more flexibility on the incoming side as well as the outgoing side.I haven't looked at how this would intersect with http3/UDP support.
Describe alternatives you've considered
hyper::body::Incoming
)The text was updated successfully, but these errors were encountered: