Skip to content

Commit 54e0757

Browse files
g2pdjc
authored andcommitted
builder: Require alpn_protocols to be empty when passing ClientConfig
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.
1 parent 129b0a0 commit 54e0757

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/connector/builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ impl ConnectorBuilder<WantsTlsConfig> {
3737

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

@@ -126,8 +128,8 @@ pub struct WantsProtocols1 {
126128
}
127129

128130
impl WantsProtocols1 {
129-
fn wrap_connector<H>(mut self, conn: H) -> HttpsConnector<H> {
130-
self.tls_config.alpn_protocols.clear();
131+
fn wrap_connector<H>(self, conn: H) -> HttpsConnector<H> {
132+
assert!(self.tls_config.alpn_protocols.is_empty());
131133
HttpsConnector {
132134
force_https: self.https_only,
133135
http: conn,

0 commit comments

Comments
 (0)