-
Notifications
You must be signed in to change notification settings - Fork 96
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
How can use hyper-tls for server #25
Comments
Not really... But I'd welcome adding some API to ease this! |
@seanmonstar I was just about to open a similar issue for this. As you're looking for a PR, do you have preferences around what this API would look like or should I submit the PR and review it then? |
I haven't thought much about it, if you want to suggest something now, I can comment, or we can just review in a PR. |
@seanmonstar My initial thoughts are, for starters, to provide |
Sure! |
PR #28 created. Lemme know if you have any feedback there. Thanks! |
I've gotten a working example with |
One approach is implementing the trait |
I see that Warp has an implementation of all this. Would it be an option to move that implementation here? |
@timbru sort of! Warp uses rustls, while this crate is currently using native-tls. However, it'd be a fine place to start, and just adapt to the native-tls types. |
@seanmonstar do you mean that it should use native-tls directly? Or could it be built on existing work in tokio-tls? I need to do more research - I am fairly new to this - but it seems to implement a lot of what is needed, and it's already a dependency. |
I just meet the same problem, and after searching, I found that maybe it's not hyper's duty to do, but tokio. the "tokio-rustls" crate gives a demo, https://github.com/tokio-rs/tls/blob/master/tokio-rustls/examples/server/src/main.rs, it show that after get a tcp stream, wrap it to a tls stream, and pass it to the http handler. I also found that hyper can deal with request in connection level, so i think the way is,
|
Thanks to @HunterGitHub, I found Full example linked HERE (w/details on using openssl/curl/wget) The main two differences from @HunterGitHub's example is auto http1/http2 upgrading, and use of TokioIo. I am really curious how and what @seanmonstar would refactor from native_tls and tokio_native_tls into hyper-hls to create the server functionality. async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
Ok(Response::new(Full::new(Bytes::from("Hello, World!"))))
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Bind the server's socket
let addr = "127.0.0.1:12345".to_string();
let listen: TcpListener = TcpListener::bind(&addr).await?;
let pem = include_bytes!("cert.pem");
let key = include_bytes!("key.pem");
let cert = Identity::from_pkcs8(pem, key)?;
let tls_acceptor = native_tls::TlsAcceptor::builder(cert).build()?;
let tls_acceptor = tokio_native_tls::TlsAcceptor::from(tls_acceptor);
loop {
let (socket, _) = listen.accept().await?;
let tls_acceptor = tls_acceptor.clone();
let server = auto::Builder::new(TokioExecutor::new()); //http1 or http2
tokio::spawn(async move {
let tls_stream = tls_acceptor.accept(socket).await.unwrap();
let io = TokioIo::new(tls_stream);
let service = service_fn(hello);
server.serve_connection(io, service).await.unwrap()
});
}
} |
Hi,
Is it possible use hyper-tls for hyper server "0.12" ?
The text was updated successfully, but these errors were encountered: