Skip to content

Commit

Permalink
builder: Require alpn_protocols to be empty when passing ClientConfig
Browse files Browse the repository at this point in the history
This is the default for a rustls ClientConfig.  We assert this
to be future proof in case we want to extend the interface by
handling pre-defined alpn_protocols later.
  • Loading branch information
g2p authored and djc committed Nov 15, 2021
1 parent 129b0a0 commit 54e0757
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/connector/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ impl ConnectorBuilder<WantsTlsConfig> {

/// Passes a rustls [`ClientConfig`] to configure the TLS connection
///
/// The [`alpn_protocols`](ClientConfig::alpn_protocols) field will be rewritten to
/// match the enabled schemes (see
/// The [`alpn_protocols`](ClientConfig::alpn_protocols) field is
/// required to be empty (or the function will panic) and will be
/// rewritten to match the enabled schemes (see
/// [`enable_http1`](ConnectorBuilder::enable_http1),
/// [`enable_http2`](ConnectorBuilder::enable_http2)) before the
/// connector is built.
pub fn with_tls_config(self, config: ClientConfig) -> ConnectorBuilder<WantsSchemes> {
assert!(config.alpn_protocols.is_empty());
ConnectorBuilder(WantsSchemes { tls_config: config })
}

Expand Down Expand Up @@ -126,8 +128,8 @@ pub struct WantsProtocols1 {
}

impl WantsProtocols1 {
fn wrap_connector<H>(mut self, conn: H) -> HttpsConnector<H> {
self.tls_config.alpn_protocols.clear();
fn wrap_connector<H>(self, conn: H) -> HttpsConnector<H> {
assert!(self.tls_config.alpn_protocols.is_empty());
HttpsConnector {
force_https: self.https_only,
http: conn,
Expand Down

0 comments on commit 54e0757

Please sign in to comment.