Is your feature request related to a problem? Please describe.
I'm implementing some code that tries to detect whether the contents of a hyper upgraded connection can be handled or should be forwarded, for this, I need to peek 4KB and decide. Even though Read seems to be more of an BufRead, hyper do not expose any peeking methods on its usual APIs, so I would need to implement my own buffering, ending up with double buffers.
Describe the solution you'd like
- Add a
Peek trait, implement it for Rewind<T>
- Implement it for
Upgraded, H2Upgraded
- Implement compat with
AsyncReadBuf for tokio.
Describe alternatives you've considered
Additional context
I have some prototype of this feature modulo the tests, the only controversial aspect is, this is my Peek trait:
pub trait Peek {
# Compared to all the other APIs, this returns a borrow of self. This should be fine lifetime-wise.
fn poll_peek(self: Pin<&mut Self>, cx: &mut Context<'_>)
-> Poll<Result<&[u8], std::io::Error>>;
fn consume(self: Pin<&mut Self>, amt: usize);
}
If you are interested, I can try to finish my tests and PR this up.
Is your feature request related to a problem? Please describe.
I'm implementing some code that tries to detect whether the contents of a hyper upgraded connection can be handled or should be forwarded, for this, I need to peek 4KB and decide. Even though
Readseems to be more of anBufRead, hyper do not expose any peeking methods on its usual APIs, so I would need to implement my own buffering, ending up with double buffers.Describe the solution you'd like
Peektrait, implement it forRewind<T>Upgraded,H2UpgradedAsyncReadBuffor tokio.Describe alternatives you've considered
Additional context
I have some prototype of this feature modulo the tests, the only controversial aspect is, this is my
Peektrait:If you are interested, I can try to finish my tests and PR this up.