-
Notifications
You must be signed in to change notification settings - Fork 114
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
feat(service): add adapter for tower services #46
Conversation
src/server/conn/auto.rs
Outdated
let (version, io) = read_version(io).await?; | ||
let io = TokioIo::new(io); | ||
match version { | ||
Version::H1 => { | ||
self.http1 | ||
.serve_connection(io, TowerToHyperService::new(service)) | ||
.await? | ||
} | ||
Version::H2 => { | ||
self.http2 | ||
.serve_connection(io, TowerToHyperService::new(service)) | ||
.await? | ||
} | ||
} | ||
|
||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd just call serve_connection
but that requires S: 'static
. Not totally sure why that is. Copy-pasting the impl doesn't require that 🤔
82fd274
to
b4c9203
Compare
#[cfg(all( | ||
any(feature = "http1", feature = "http2"), | ||
any(feature = "server", feature = "client") | ||
))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps hyper should have a service
feature so we don't need to do stuff like this.
b4c9203
to
12d7a60
Compare
any(feature = "http1", feature = "http2"), | ||
any(feature = "server", feature = "client") | ||
))] | ||
pub async fn serve_connection_tower<I, S, B>(&self, io: I, service: S) -> Result<()> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been thinking that axum also needs a version that uses MakeService
for https://docs.rs/axum/latest/axum/struct.Router.html#method.into_make_service_with_connect_info
I wanna do some more thinking about how to best do this. So I'll close this PR for now and submit PRs with smaller pieces. |
This adds
TowerToHyperService
which converts a tower service into a hyper service.Builder::serve_connection_tower
andBuilder::serve_connection_with_upgrades_tower
for serving a tower service directly. The adapter will be applied internally.