Skip to content
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

Chore(deps): hyper 1.0 #126

Merged
merged 41 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2dd0d4a
feat(engineio): hyper 1.0.0
Totodore Oct 22, 2023
9835880
feat(engineio/payload): switch to http-body-util
Totodore Oct 22, 2023
4133f9d
fix(engineio/test): fix hyper for testing
Totodore Oct 23, 2023
f5f8855
fix(socketio/test): fix hyper for testing
Totodore Oct 23, 2023
da112bb
feat(socketio/service): migrate to hyper 1.0 service
Totodore Oct 23, 2023
a649973
Revert "feat(socketio/service): migrate to hyper 1.0 service"
Totodore Oct 26, 2023
ff2ce87
Revert "fix(socketio/test): fix hyper for testing"
Totodore Oct 26, 2023
fc23023
Revert "fix(engineio/test): fix hyper for testing"
Totodore Oct 26, 2023
059daa6
Revert "feat(engineio/payload): switch to http-body-util"
Totodore Oct 26, 2023
eb84ee4
Revert "feat(engineio): hyper 1.0.0"
Totodore Oct 26, 2023
8af7229
Merge branch 'main' into chore(deps)-hyper-1.0
Totodore Oct 26, 2023
c532ecf
chore(deps): add optional dependencies for hyper v1
Totodore Oct 26, 2023
c54dca0
feat(engineio/body): implement Body V1 for the `ResponseBody` type
Totodore Oct 26, 2023
e961062
refactor(engineio): distinct server and services modules
Totodore Oct 26, 2023
60e69ed
refactor(engineio/service): keep a separate service mod
Totodore Oct 26, 2023
5979346
fix(ci): fix testing with protocol features without hyper 1.0
Totodore Oct 26, 2023
7add296
chore(ci): add tracing feature for testing
Totodore Oct 28, 2023
4ca39cd
fix(engineio/service): hyper service imports
Totodore Oct 28, 2023
0eb3b2b
fix(engineio/service): remove http body v0.4 bound for hyper v1
Totodore Oct 28, 2023
da6653a
refactor(examples): split examples between libraries
Totodore Oct 28, 2023
507a64a
docs(examples): add salvo echo examples
Totodore Oct 28, 2023
92f411d
Merge remote-tracking branch 'origin/main' into chore(deps)-hyper-1.0
Totodore Oct 30, 2023
2505372
docs(examples): fix salvo echo router
Totodore Oct 30, 2023
c0558c6
fix(engineio/body): fix non generic `Empty` http body type
Totodore Oct 30, 2023
ab4edc4
doc(examples): add a hyper_v1_service
Totodore Oct 30, 2023
d549e61
feat(engineio/service): make a wrapper for hyper 1.0 svc
Totodore Oct 30, 2023
fa5b705
fix(engineio/hyper): make `NotFoundService` compatible with hyper v1
Totodore Oct 30, 2023
b009e04
fix(engineio/layer): missing cfg flag
Totodore Oct 30, 2023
a53646a
fix(engineio/test): remove hyper-v1 flag check
Totodore Oct 30, 2023
8833d58
chore(ci): add hyper versions to ci tests
Totodore Oct 30, 2023
ca6d3bd
chore(ci): rename hyper version matrix
Totodore Oct 30, 2023
1f76bf6
fix(e2e): disable optional `hyper-v1` dep
Totodore Nov 1, 2023
4c0e893
fix(e2e): enable hyper upgrades
Totodore Nov 1, 2023
40af096
fix(engineio/ws): upgrade with `hyper_v1` when it is enabled
Totodore Nov 1, 2023
97d030f
fix(clippy): clippy alterts about &str
Totodore Nov 1, 2023
06433b8
doc(example): remove config from `salvo_echo`
Totodore Nov 1, 2023
6ba81de
feat(socketio/service): add support for hyper 1.0
Totodore Nov 1, 2023
72b9cc0
doc(example): update salvo echo example to work with socket.io
Totodore Nov 1, 2023
7fd0550
doc(example): update hyper-v1-echo example
Totodore Nov 1, 2023
9191bc2
docs(socketio/layer): improve doc
Totodore Nov 1, 2023
57c7dda
docs: update CHANGELOG
Totodore Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
789 changes: 742 additions & 47 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions engineioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ tracing = { version = "0.1.37", optional = true }
memchr = { version = "2.5.0", optional = true }
unicode-segmentation = { version = "1.10.1", optional = true }

# Hyper v1.0
hyper-v1 = { package = "hyper", version = "1.0.0-rc.4", optional = true, features = [
"server",
"http1",
"http2",
] }
http-body-v1 = { package = "http-body", version = "1.0.0-rc.2", optional = true }

[dev-dependencies]
tokio = { version = "1.26.0", features = ["macros", "parking_lot"] }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
Expand All @@ -58,3 +66,4 @@ v4 = []
v3 = ["memchr", "unicode-segmentation"]
test-utils = []
tracing = ["dep:tracing"]
hyper-v1 = ["dep:hyper-v1", "dep:http-body-v1"]
101 changes: 0 additions & 101 deletions engineioxide/src/body.rs

This file was deleted.

4 changes: 4 additions & 0 deletions engineioxide/src/body/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(feature = "hyper-v1")]
pub mod request;

pub mod response;
101 changes: 101 additions & 0 deletions engineioxide/src/body/request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//! Custom Request Body compat struct implementation to map [`http_body_v1::Body`] to a [`http_body::Body`]
//! Only enabled with the feature flag `hyper-v1`
//!
//! Eavily inspired from : /~https://github.com/davidpdrsn/tower-hyper-http-body-compat

use std::{
pin::Pin,
task::{Context, Poll},
};

use http::HeaderMap;
use pin_project::pin_project;

/// Wraps a body to implement the [`http_body::Body`] on it
#[pin_project]
pub struct IncomingBody<B> {
#[pin]
body: B,
trailers: Option<HeaderMap>,
}
impl<B> IncomingBody<B> {
pub fn new(body: B) -> IncomingBody<B> {
IncomingBody {
body,
trailers: None,
}
}
}

impl<B> http_body::Body for IncomingBody<B>
where
B: http_body_v1::Body,
{
type Data = B::Data;
type Error = B::Error;

fn poll_data(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
let this = self.project();
match futures::ready!(this.body.poll_frame(cx)) {
Some(Ok(frame)) => {
let frame = match frame.into_data() {
Ok(data) => return Poll::Ready(Some(Ok(data))),
Err(frame) => frame,
};

match frame.into_trailers() {
Ok(trailers) => {
*this.trailers = Some(trailers);
}
Err(_frame) => {}
}

Poll::Ready(None)
}
Some(Err(err)) => Poll::Ready(Some(Err(err))),
None => Poll::Ready(None),
}
}

fn poll_trailers(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
loop {
let this = self.as_mut().project();

if let Some(trailers) = this.trailers.take() {
break Poll::Ready(Ok(Some(trailers)));
}

match futures::ready!(this.body.poll_frame(cx)) {
Some(Ok(frame)) => match frame.into_trailers() {
Ok(trailers) => break Poll::Ready(Ok(Some(trailers))),
// we might get a trailers frame on next poll
// so loop and try again
Err(_frame) => {}
},
Some(Err(err)) => break Poll::Ready(Err(err)),
None => break Poll::Ready(Ok(None)),
}
}
}

fn size_hint(&self) -> http_body::SizeHint {
let size_hint = self.body.size_hint();
let mut out = http_body::SizeHint::new();
out.set_lower(size_hint.lower());
if let Some(upper) = size_hint.upper() {
out.set_upper(upper);
}
out
}

#[inline]
fn is_end_stream(&self) -> bool {
self.body.is_end_stream()
}
}
Loading
Loading