Hi,
I'm trying to update tokio-tls to be usable with latest tokio and hyper. Most of things is working , but still have some issues with hyper-server example:
pub fn main() {
// Create our TLS context through which new connections will be
// accepted. This is where we pass in the certificate as well to
// send to clients.
let der = include_bytes!("identity.p12");
let cert = Identity::from_pkcs12(der, "mypass").unwrap();
let tls_cx = TlsAcceptor::builder(cert).build().unwrap();
let new_service = || service_fn_ok(|_req| Response::new(Body::from("Hello World")));
let addr = "127.0.0.1:12345".parse().unwrap();
let srv = TcpListener::bind(&addr).expect("Error binding local port");
// Use lower lever hyper API to be able to intercept client connection
let http_proto = Http::new();
let http_server = http_proto
.serve_incoming(
srv.incoming().and_then(move |socket| {
tls_cx
.accept_async(socket)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
}),
new_service,
)
.for_each(|conn| {
hyper::rt::spawn(
conn.and_then(|c| c.map_err(|e| panic!("Hyper error {}", e)))
.map_err(|e| eprintln!("Connection error {}", e)),
);
Ok(())
});
println!("Listening on {}", addr);
hyper::rt::run(http_server.map_err(|e| eprintln!("Error running server: {}", e)));
}
Now I got 2 problems (maybe related) - the only way to make this compile is to use panic!
in err_map. Otherwise I really cannot find appropriate mapping due to this error:
type mismatch resolving `<[closure@examples/hyper-server.rs:56:45: 56:79] as std::ops::FnOnce<(hyper::Error,)>>::Output == hyper::common::never::Never`
expected (), found enum `hyper::common::never::Never`
Above code somehow runs, but problem is when there is some error in the connection (like for instance using http:// schema in browser - then TLS handshake fails) - then severs stops responding to further connections - all connections are refused.
What could be the problem - do you see anything wrong in the code above? Any ideas?
full code for updated tokio-tls including this example is here https://github.com/izderadicka/tokio-tls/tree/new-tokio