Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connector: enable_all_versions with matching alpn vs features #224

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

TimLuq
Copy link
Contributor

@TimLuq TimLuq commented Oct 3, 2023

Fixes #208

The original intent of this function is slightly confusing. As it was implemented before, it required all supported protocol features to be enabled for the function to exist (both http1 and http2). My naive guess would have been that the expected behavior is that all enabled protocol features would inform the actual functionality, but the function would still show up if at least one protocol is enabled.

I understand that having this completely dynamic based on active features would muddle the documented return type and be breaking depending on active features. Either way, to me, it hurt a bit working on a function named enable_all_versions with a strict feature requirement on the non-default optional feature http2. But now it should work correctly in the previously intended use cases.

Changes to enable_all_versions

  • drop strict requirement of the http1 feature
  • add feature requirement http2 to fn docs (previously a non-documented requirement)
  • alpn will only contain h2 if http1 is not enabled
  • alpn will contain h2 and http/1.1 if both features are enabled

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably makes sense (and makes the interface easier to understand). @cpu any thoughts?

@@ -174,16 +174,22 @@ impl ConnectorBuilder<WantsProtocols1> {
})
}

/// Enable all HTTP versions
/// Enable all HTTP versions built into this library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this more explicit, like (enabled with Cargo features)?

Comment on lines +181 to +182
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do this, let's get rid of the http2 guard? And make it work for all of the possible combinations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that seems like the right direction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djc

The problem with not having the http2 guard is that the return type would change (since WantsProtocols3 wont exist). So if any library enables the feature it might cause other libraries to not compile if they expected WantsProtocols2. Since enabling an extra feature in a deep dependency doesn't usually warrant a major version release, things in the wild could spontaneously break if one single library enables it when one other doesn't expect it.

Making the feature combination non-breaking would require wrapping the actual inner type WantsProtocolsN (based on the highest enabled protocol feature) in a WantsProtocolsAll singleton struct and always returning that. That would be a breaking change for this library, however, which is why I didn't want to do it in this fix.

If a version of this fix gets merged I could create a new PR with the above solution with a new breaking return type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable, I'd be willing to merge this in order to get this improvement out provided you submit an additional PR to do the semver-breaking fix.

@@ -335,5 +341,14 @@ mod tests {
&connector.tls_config.alpn_protocols,
&[b"h2".to_vec(), b"http/1.1".to_vec()]
);
let connector = super::ConnectorBuilder::new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is only checking the result of using enable_all_versions with both the http1 and http2 feature flags enabled based on the guard on test_alpn. Ideally we could assert the correct state for more combinations than just this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we could assert the correct state for more combinations than just this case.

Yeah, I realized this too. I locally created an additional test case for only http2 while I was writing the PR description. I suspected that I'd get feedback on the doc line so I didn't want to muddy the waters with an additional small commit. But I'll push it now.

Comment on lines +181 to +182
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable, I'd be willing to merge this in order to get this improvement out provided you submit an additional PR to do the semver-breaking fix.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :-)

src/connector/builder.rs Show resolved Hide resolved
@djc djc merged commit fcb72be into rustls:main Oct 5, 2023
9 checks passed
@djc
Copy link
Member

djc commented Oct 5, 2023

Thanks!

@cpu
Copy link
Member

cpu commented Oct 5, 2023

+1, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpsConnectorBuilder::enable_all_versions doesn't enable ALPN for http/1.1
3 participants