| 1 | //! # hyper-rustls |
| 2 | //! |
| 3 | //! A pure-Rust HTTPS connector for [hyper](https://hyper.rs), based on |
| 4 | //! [Rustls](https://github.com/rustls/rustls). |
| 5 | //! |
| 6 | //! ## Example client |
| 7 | //! |
| 8 | //! ```no_run |
| 9 | //! # #[cfg (all(feature = "rustls-native-certs" , feature = "http1" ))] |
| 10 | //! # fn main() { |
| 11 | //! use http::StatusCode; |
| 12 | //! use http_body_util::Empty; |
| 13 | //! use hyper::body::Bytes; |
| 14 | //! use hyper_util::client::legacy::Client; |
| 15 | //! use hyper_util::rt::TokioExecutor; |
| 16 | //! |
| 17 | //! let mut rt = tokio::runtime::Runtime::new().unwrap(); |
| 18 | //! let url = ("https://hyper.rs" ).parse().unwrap(); |
| 19 | //! let https = hyper_rustls::HttpsConnectorBuilder::new() |
| 20 | //! .with_native_roots() |
| 21 | //! .expect("no native root CA certificates found" ) |
| 22 | //! .https_only() |
| 23 | //! .enable_http1() |
| 24 | //! .build(); |
| 25 | //! |
| 26 | //! let client: Client<_, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(https); |
| 27 | //! |
| 28 | //! let res = rt.block_on(client.get(url)).unwrap(); |
| 29 | //! assert_eq!(res.status(), StatusCode::OK); |
| 30 | //! # } |
| 31 | //! # #[cfg (not(all(feature = "rustls-native-certs" , feature = "http1" )))] |
| 32 | //! # fn main() {} |
| 33 | //! ``` |
| 34 | |
| 35 | #![warn (missing_docs, unreachable_pub, clippy::use_self)] |
| 36 | #![cfg_attr (docsrs, feature(doc_cfg, doc_auto_cfg))] |
| 37 | |
| 38 | mod config; |
| 39 | mod connector; |
| 40 | mod stream; |
| 41 | |
| 42 | #[cfg (feature = "logging" )] |
| 43 | mod log { |
| 44 | #[cfg (any(feature = "rustls-native-certs" , feature = "webpki-roots" ))] |
| 45 | pub(crate) use log::debug; |
| 46 | #[cfg (feature = "rustls-native-certs" )] |
| 47 | pub(crate) use log::warn; |
| 48 | } |
| 49 | |
| 50 | #[cfg (not(feature = "logging" ))] |
| 51 | mod log { |
| 52 | #[cfg (any(feature = "rustls-native-certs" , feature = "webpki-roots" ))] |
| 53 | macro_rules! debug ( ($($tt:tt)*) => {{}} ); |
| 54 | #[cfg (any(feature = "rustls-native-certs" , feature = "webpki-roots" ))] |
| 55 | pub(crate) use debug; |
| 56 | #[cfg (feature = "rustls-native-certs" )] |
| 57 | macro_rules! warn_ ( ($($tt:tt)*) => {{}} ); |
| 58 | #[cfg (feature = "rustls-native-certs" )] |
| 59 | pub(crate) use warn_ as warn; |
| 60 | } |
| 61 | |
| 62 | pub use crate::config::ConfigBuilderExt; |
| 63 | pub use crate::connector::builder::ConnectorBuilder as HttpsConnectorBuilder; |
| 64 | pub use crate::connector::{ |
| 65 | DefaultServerNameResolver, FixedServerNameResolver, HttpsConnector, ResolveServerName, |
| 66 | }; |
| 67 | pub use crate::stream::MaybeHttpsStream; |
| 68 | |
| 69 | /// The various states of the [`HttpsConnectorBuilder`] |
| 70 | pub mod builderstates { |
| 71 | #[cfg (feature = "http2" )] |
| 72 | pub use crate::connector::builder::WantsProtocols3; |
| 73 | pub use crate::connector::builder::{ |
| 74 | WantsProtocols1, WantsProtocols2, WantsSchemes, WantsTlsConfig, |
| 75 | }; |
| 76 | } |
| 77 | |