Skip to content

Offer a Peek interface over Upgraded connections #4144

Description

@RaitoBezarius

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

  • Do the buffering myself.

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-rtArea: runtime traits/utilsC-featureCategory: feature. This is adding a new feature.S-waiting-on-reviewStatus: waiting on review.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions