From 180050020e712d38d98c8fee49ac119b147ebd06 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 20 Aug 2019 14:26:43 +0100 Subject: [PATCH] Address review comments --- httpx/config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/httpx/config.py b/httpx/config.py index 08b99c0d..b8544453 100644 --- a/httpx/config.py +++ b/httpx/config.py @@ -16,6 +16,8 @@ HTTPVersionTypes = typing.Union[ USER_AGENT = f"python-httpx/{__version__}" +HTTP_VERSIONS_TO_ALPN_IDENTIFIERS = {"HTTP/1.1": "http/1.1", "HTTP/2": "h2"} + DEFAULT_CIPHERS = ":".join( [ "ECDHE+AESGCM", @@ -160,9 +162,9 @@ class SSLConfig: context.set_ciphers(DEFAULT_CIPHERS) if ssl.HAS_ALPN: - context.set_alpn_protocols(http_versions.alpn_strings) + context.set_alpn_protocols(http_versions.alpn_identifiers) if ssl.HAS_NPN: # pragma: no cover - context.set_npn_protocols(http_versions.alpn_strings) + context.set_npn_protocols(http_versions.alpn_identifiers) return context @@ -260,12 +262,13 @@ class HTTPVersionConfig: raise ValueError(f"HTTP versions cannot be an empty list.") @property - def alpn_strings(self) -> typing.List[str]: + def alpn_identifiers(self) -> typing.List[str]: """ Returns a list of supported ALPN identifiers. (One or more of "http/1.1", "h2"). """ - mapping = {"HTTP/1.1": "http/1.1", "HTTP/2": "h2"} - return [mapping[version] for version in self.http_versions] + return [ + HTTP_VERSIONS_TO_ALPN_IDENTIFIERS[version] for version in self.http_versions + ] def __repr__(self) -> str: class_name = self.__class__.__name__ -- 2.47.3