Crate hyper_tls_hack[−][src]
An implementation of hyper
's AddrIncoming
that generates TlsStream
s.
Right now the server part of hyper
0.12 does not support TLS
. There
is not a simple and correct implementation available that just
"plugs in" to hyper
.
The latest tokio_tls
does have an example how to use it with hyper
,
but then you miss out on an important part of hyper
, implemented in
hyper::server::conn::AddrIncoming
, that retries when accept()
fails (which it intermittently can).
Otherwise your server might unexpectedly die at an inconvenient time.
So, this crate is just a hack of hyper
's AddrIncoming
that
supports tokio_tls
.
So why is it called hyper-tls-hack
? Well for 3 reasons actually:
- this is my first crate
- I might be using unstable interfaces of
hyper
and it might stop working after the nexthyper
minor release - I assume that soon there will be an "official" way to do this.
Example server:
extern crate hyper; extern crate hyper_tls_hack; use std::sync::Arc; use hyper::{Body, Response, Server}; use hyper::rt::Future; use hyper::service::service_fn_ok; static TEXT: &str = "Hello, HTTPS World!\n"; fn main() { let addr = ([0, 0, 0, 0], 8445).into(); let new_svc = || { service_fn_ok(|_req|{ Response::new(Body::from(TEXT)) }) }; let acceptor = Arc::new(hyper_tls_hack::acceptor_from_p12_file("cert.p12", "").unwrap()); let mut ai = hyper_tls_hack::AddrIncoming::new(&addr, acceptor, None).expect("addrincoming error"); ai.set_nodelay(true); let server = Server::builder(ai) .serve(new_svc) .map_err(|e| eprintln!("server error: {}", e)); println!("Listening HTTPS on: {}", addr); hyper::rt::run(server); }
Structs
AddrIncoming |
A stream of TLS connections from binding to an address. |
Functions
acceptor_from_p12_file |
Simple utility function that reads a certificate file, and returns a TlsAcceptor. Useful for examples in documentation :) |