How to use the httpx.config.SSLConfig function in httpx

To help you get started, weā€™ve selected a few httpx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config_verify_existing_file():
    ssl_config = SSLConfig(verify=certifi.where())
    context = ssl_config.load_ssl_context()
    assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
    assert context.check_hostname is True
github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config_no_verify():
    ssl_config = SSLConfig(verify=False)
    context = ssl_config.load_ssl_context()
    assert context.verify_mode == ssl.VerifyMode.CERT_NONE
    assert context.check_hostname is False
github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config_cert_and_encrypted_key(
    cert_pem_file, cert_encrypted_private_key_file, password
):
    ssl_config = SSLConfig(
        cert=(cert_pem_file, cert_encrypted_private_key_file, password)
    )
    context = ssl_config.load_ssl_context()
    assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
    assert context.check_hostname is True
github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config():
    ssl_config = SSLConfig()
    context = ssl_config.load_ssl_context()
    assert context.verify_mode == ssl.VerifyMode.CERT_REQUIRED
    assert context.check_hostname is True
github encode / httpx / tests / test_concurrency.py View on Github external
async def test_start_tls_on_uds_socket_stream(https_uds_server):
    backend = lookup_backend()
    ctx = SSLConfig().load_ssl_context_no_verify()
    timeout = Timeout(5)

    stream = await backend.open_uds_stream(
        https_uds_server.config.uds, https_uds_server.url.host, None, timeout
    )

    try:
        assert stream.is_connection_dropped() is False
        assert get_cipher(backend, stream) is None

        stream = await stream.start_tls(https_uds_server.url.host, ctx, timeout)
        assert stream.is_connection_dropped() is False
        assert get_cipher(backend, stream) is not None

        await stream.write(b"GET / HTTP/1.1\r\n\r\n", timeout)
github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config_cert_without_key_raises(cert_pem_file):
    ssl_config = SSLConfig(cert=cert_pem_file)
    with pytest.raises(ssl.SSLError):
        ssl_config.load_ssl_context()
github encode / httpx / tests / test_config.py View on Github external
def test_load_ssl_config_cert_and_key_invalid_password(
    cert_pem_file, cert_encrypted_private_key_file
):
    ssl_config = SSLConfig(
        cert=(cert_pem_file, cert_encrypted_private_key_file, "password1")
    )

    with pytest.raises(ssl.SSLError):
        ssl_config.load_ssl_context()
github encode / httpx / tests / test_config.py View on Github external
def test_ssl_eq():
    ssl = SSLConfig(verify=False)
    assert ssl == SSLConfig(verify=False)
github encode / httpx / tests / test_config.py View on Github external
def test_ssl_repr():
    ssl = SSLConfig(verify=False)
    assert repr(ssl) == "SSLConfig(cert=None, verify=False)"
github encode / httpx / httpx / config.py View on Github external
def with_overrides(
        self, cert: CertTypes = None, verify: VerifyTypes = None
    ) -> "SSLConfig":
        cert = self.cert if cert is None else cert
        verify = self.verify if verify is None else verify
        if (cert == self.cert) and (verify == self.verify):
            return self
        return SSLConfig(cert=cert, verify=verify)