http-rs / http-types

Common types for HTTP operations
https://docs.rs/http-types
Apache License 2.0
200 stars 83 forks source link

Allow Body to have a borrowed reader #316

Open Dirbaio opened 3 years ago

Dirbaio commented 3 years ago

Thinking about the complexity in async-h1 around cloning the readers, it occurred to me that most of it would go away if Request could have a borrowed body reader.

cc @jbr

It'd be something like this:

    pub struct Body<'a> {
        reader: &'a mut dyn AsyncRead + Unpin + Send + Sync,
        ...
    }
    pub struct Request<'a> {
        body: Body<'a>,
        ...
    }
jbr commented 3 years ago

I agree that this sense in the abstract, but I believe having a lifetime on Request would be a problem for tide, which needs static lifetimes on arguments to endpoints

Fishrock123 commented 3 years ago

We could maybe allow Body to have an Arc'd reader, though. (If that doesn't already work.)

Fishrock123 commented 3 years ago

@yoshuawuyts I think this is also gated on the whole async closures thing.