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

feat(service): add adapter for tower services #46

Closed
wants to merge 1 commit into from

Conversation

davidpdrsn
Copy link
Member

This adds

  • TowerToHyperService which converts a tower service into a hyper service.
  • Builder::serve_connection_tower and Builder::serve_connection_with_upgrades_tower for serving a tower service directly. The adapter will be applied internally.
  • An example showing how to use it since there was previously only a client example.

Comment on lines 103 to 121
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(())
Copy link
Member Author

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 🤔

@davidpdrsn davidpdrsn force-pushed the serve-tower branch 2 times, most recently from 82fd274 to b4c9203 Compare November 10, 2023 13:14
Comment on lines +11 to +14
#[cfg(all(
any(feature = "http1", feature = "http2"),
any(feature = "server", feature = "client")
))]
Copy link
Member Author

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.

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<()>
Copy link
Member Author

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

@davidpdrsn
Copy link
Member Author

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.

@davidpdrsn davidpdrsn closed this Nov 23, 2023
@davidpdrsn davidpdrsn deleted the serve-tower branch November 23, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant