This commit is contained in:
Jakub Roztocil 2020-05-23 20:30:25 +02:00
parent 4c4efff56a
commit 27d57ce773
2 changed files with 21 additions and 13 deletions

View File

@ -9,6 +9,8 @@ from typing import Iterable, Union
from urllib.parse import urlparse, urlunparse
import requests
# noinspection PyPackageRequirements
import urllib3
from httpie import __version__
from httpie.cli.dicts import RequestHeadersDict
@ -18,15 +20,7 @@ from httpie.ssl import AVAILABLE_SSL_VERSION_ARG_MAPPING, HTTPieHTTPSAdapter
from httpie.utils import repr_dict
try:
# noinspection PyPackageRequirements
import urllib3
# <https://urllib3.readthedocs.io/en/latest/security.html>
urllib3.disable_warnings()
except (ImportError, AttributeError):
pass
urllib3.disable_warnings()
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'
JSON_CONTENT_TYPE = 'application/json'

View File

@ -32,12 +32,11 @@ class HTTPieHTTPSAdapter(HTTPAdapter):
ciphers: str = None,
**kwargs
):
self._ssl_context = create_urllib3_context(
self._ssl_context = self._create_ssl_context(
verify=verify,
ssl_version=ssl_version,
ciphers=ciphers,
ssl_version=resolve_ssl_version(ssl_version),
cert_reqs=ssl.CERT_REQUIRED if verify else ssl.CERT_NONE
)
super().__init__(**kwargs)
def init_poolmanager(self, *args, **kwargs):
@ -47,3 +46,18 @@ class HTTPieHTTPSAdapter(HTTPAdapter):
def proxy_manager_for(self, *args, **kwargs):
kwargs['ssl_context'] = self._ssl_context
return super().proxy_manager_for(*args, **kwargs)
@staticmethod
def _create_ssl_context(
verify: bool,
ssl_version: str = None,
ciphers: str = None,
) -> ssl.SSLContext:
return create_urllib3_context(
ciphers=ciphers,
ssl_version=resolve_ssl_version(ssl_version),
# Since we are using a custom SSL context, we need to pass this
# here manually, even though its also passed to the connection
# in `super().cert_verify()`.
cert_reqs=ssl.CERT_REQUIRED if verify else ssl.CERT_NONE
)