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

Add HTTP/1.1 ALPN support #1894

Merged
merged 5 commits into from Jul 16, 2020
Merged

Conversation

hodbn
Copy link
Member

@hodbn hodbn commented Jun 25, 2020

Added ALPN support, resolves #1892.

Sending ALPN protocols (["http/1.1"]) by default, if backend support is available.

TODO:

  • Better testing of ALPN support.
  • TestHTTPS_ALPN introduced too much tests.
  • Add SecureTransport support.

Support:

Requires Python>=2.7.9 (for SSLContext) and backend support:

  • ssl: needs OpenSSL>=1.0.2
  • PyOpenSSL: needs OpenSSL>=1.0.2, PyOpenSSL>=0.15, cryptography>=0.5
  • SecureTransport: needs macOS >= 10.12

@sethmlarson
Copy link
Member

sethmlarson commented Jun 25, 2020

I wonder if it makes sense for us to unconditionally add http/1.1 to ALPN when available similar to how httplib will be doing so now and how curl has done so for forever. That way we can skip on all the conditional / HAS_ALPN detection logic and instead detect based on whether SSLContext has set_alpn_protocols() and catch NotImplementedError.

urllib3 only speaks HTTP/1.1 (or 1.0 if server is too but we prefer not to) so I don't see the need for this to be configurable.

@pquentin
Copy link
Member

+1 to avoid adding yet another knob if we can avoid it

@pquentin
Copy link
Member

Good job so far, thanks!

@hodbn hodbn force-pushed the feature-alpn-support branch 4 times, most recently from 54abdb6 to 9457440 Compare July 5, 2020 20:52
@codecov
Copy link

codecov bot commented Jul 5, 2020

Codecov Report

Merging #1894 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #1894      +/-   ##
===========================================
+ Coverage   99.95%   100.00%   +0.04%     
===========================================
  Files          23        23              
  Lines        2049      2054       +5     
===========================================
+ Hits         2048      2054       +6     
+ Misses          1         0       -1     
Flag Coverage Δ
#unittests 99.51% <80.00%> (-0.05%) ⬇️
Impacted Files Coverage Δ
src/urllib3/util/__init__.py 100.00% <ø> (ø)
src/urllib3/util/ssl_.py 100.00% <100.00%> (ø)
src/urllib3/util/wait.py 100.00% <0.00%> (+1.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5a45dc...e756385. Read the comment docs.

@hodbn
Copy link
Member Author

hodbn commented Jul 5, 2020

I've removed API to customize ALPN protocols and most of HAS_ALPN references. Instead, I added a utility has_alpn function in order to allow precise testing.

What do you think?

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

This is stellar, thank you for all this work! 🎉 I left a few comments :)

src/urllib3/contrib/securetransport.py Outdated Show resolved Hide resolved
src/urllib3/util/ssl_.py Outdated Show resolved Hide resolved
@@ -374,6 +376,19 @@ def _set_ciphers(self):
)
_assert_no_error(result)

def _set_alpn_protocols(self, protocols):
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to confirm this works via capturing a TLS handshake on a supported platform, have we tried that yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a test in TestALPN::test_alpn_protocol_in_first_request_packet, is that what you meant?

Copy link
Member

Choose a reason for hiding this comment

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

I meant it'd be great to have an indication this all works on a live macOS 10.12+ system by verifying manually w/ Wireshark. I don't have a macOS machine so I can't help here but we can do that outside this PR though :)

test/with_dummyserver/test_socketlevel.py Show resolved Hide resolved
@hodbn hodbn requested a review from sethmlarson July 16, 2020 08:06
Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

Looks good to me :)

This was referenced Mar 15, 2021
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.

urllib3 should send http/1.1 ALPN extension by default
3 participants