-
-
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
Prepare forwards-compatibile Body trait #2840
Comments
ProposalProblemThe FramesWe want a match f {
Frame::Data(buf) => {},
Frame::Trailers(map) => {},
Frame::Unknown(raw) => {},
// #[non_exhaustive]
_ => {},
} If we were to start to "understand" a frame type that used to fall into the So, we don't want to expose an enum directly. Something like the dyn match concept would be great, but it doesn't exist yet. It'd be possible to inspect the frame using a bunch Proposed Designpub trait Body {
type Data: Buf;
fn poll_frame(..) -> Result<Option<Frame<Self::Data>>>;
}
pub struct Frame<T>(Kind<T>);
enum Kind<T> {
// The first two variants are "inlined" since they are undoubtedly
// the most common. This saves us from having to allocate a
// boxed trait object for them.
Data(T),
Trailers(HeaderMap),
Unknown(Box<dyn Frameish>),
}
/// The name is just YOLO for now.
pub trait Frameish {
fn frame_kind(&self) -> u64;
// Just a byte slice? The DATA type couldn't necessarily fulfill this...
fn payload(&self) -> &[u8];
} UsageMatchingwhile let Some(fr) = body.frame().await? {
// the macro is optional, but seems helpful
match_dyn! { fr;
frame::Data(buf) => {
},
frame::Trailers(trailers) => {
},
other => {
if other.frame_kind() == 0xF3 {
eprintln!("my custom frame: {:?}", other.payload());
} else {
// i dunno?
}
}
}
} BufferedThe let mut buffered = body.buffered();
// Buffered can poll for specific frame types
while let Some(data) = buffered.data().await? {
}
// DATA frames are done. What stopped them? A trailers frame? EOS?
if let Some(trailers) = buffered.trailers().await? {
}
// or maybe some other EOS-ish frame
if let Some(fr) = buffered.frame().await? {
// ``\_(0_0)_/``
} SendingAssume a channel where the receiver is let (tx, rx) = hyper_util::body::channel();
// give away the rx
tx.send_frame(Frame::data(buf)).await?;
tx.send_frame(Frame::trailers(map)).await?;
tx.send_frame(Frame::custom(0xF3, b"yolo")).await?; Remaining QuestionsHow does
|
cc @acfoltzer @davidpdrsn @nox @olix0r You all either maintain proxies that could need this, or previously done a lot with |
Also @LucioFranco and @rcoh. |
I'm going to move forward with this, unless anyone wants to comment. |
Oh sorry missed this, What would exist in |
Yes pretty much everything proposed here is actually for |
HTTP 2 and 3 have slightly different meanings on their frame type ids. The body may need to provide information about its underlying connection protocol. |
That's a good point. HTTP/3 tried to reuse the same IDs for equivalent frames, but there may be subtle differences, and it could be worth including a I'm moving forward with the proposal. |
This implements the core of the proposal in hyperium/hyper#2840.
Hello, @seanmonstar! @acfoltzer and I work for the same company. This is great progress and we are looking forward to seeing how custom HTTP/2 frames will be handled in hyper. At the moment we have a patched h2 crate that has special handling for our custom frame, which works fine, but it is always nice to see standard interfaces for things. A few things spring to mind related to the plan: In addition to What do you think would be the best way to represent custom frames exchanged before the headers frame? In our internal HTTP/2-based protocol a custom frame with a stream id can precede the headers frame. In that case, rather than the headers frame creating the new stream, it is the custom frame that creates it. We use the We also use custom settings, though this is getting further and further away from the topic of the |
Hm, yea, flags would be good to support too. Would you like to push forward on exploring the design for custom frames? I've got a deadline for a hyper 1.0 release candidate soon, and so my main priority is getting the types in place, such as
The design doesn't accommodate that at all, since I've been assuming what it says in the spec is that it's illegal:
I... think at that point I'd probably customize at the codec level, like the |
This implements the core of the proposal in hyperium/hyper#2840.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
The `Body` trait was adjusted to be forwards compatible with adding new frame types. That resulted in changing from `poll_data` and `poll_trailers` to a single `poll_frame` function. More can be learned from the proposal in #2840. Closes #3010 BREAKING CHANGE: The polling functions of the `Body` trait have been redesigned. The free functions `hyper::body::to_bytes` and `aggregate` have been removed. Similar functionality is on `http_body_util::BodyExt::collect`.
hyper 0.14.x provided a collection of interfaces related to collecting and aggregating request and response bodies, which were deprecated and removed in the 1.x major release. this commit updates calls to `hyper::body::to_bytes(..)` and `hyper::body::aggregate(..)`. for now, `http_body::Body` is used, but we can use `http_body_util::BodyExt` once we've bumped our hyper dependency to the 1.x major release. for more information, see: * linkerd/linkerd2#8733 * hyperium/hyper#2840 * hyperium/hyper#3020 Signed-off-by: katelyn martin <kate@buoyant.io>
* chore(app/admin): add `http-body` dependency before we address deprecated hyper interfaces related to `http_bodies`, we'll want to add this dependency so that we can call `Body::collect()`. Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(app): update deprecated hyper body calls hyper 0.14.x provided a collection of interfaces related to collecting and aggregating request and response bodies, which were deprecated and removed in the 1.x major release. this commit updates calls to `hyper::body::to_bytes(..)` and `hyper::body::aggregate(..)`. for now, `http_body::Body` is used, but we can use `http_body_util::BodyExt` once we've bumped our hyper dependency to the 1.x major release. for more information, see: * linkerd/linkerd2#8733 * hyperium/hyper#2840 * hyperium/hyper#3020 Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
We want to explore a trait that can be forwards-compatible in frame types for a body stream.
Steps:
http-body
crate.The text was updated successfully, but these errors were encountered: