def test_tls_upgrade(self, monkeypatch): monkeypatch.setattr(hyper.common.connection, 'HTTP11Connection', DummyH1Connection) monkeypatch.setattr(hyper.common.connection, 'HTTP20Connection', DummyH2Connection) c = HTTPConnection('test', 443) assert isinstance(c._conn, DummyH1Connection) r = c.request('GET', '/') assert r == 'h2' assert isinstance(c._conn, DummyH2Connection) assert c._conn._sock == 'totally a secure socket'
def test_http_upgrade(self, monkeypatch): monkeypatch.setattr(hyper.common.connection, 'HTTP11Connection', DummyH1Connection) monkeypatch.setattr(hyper.common.connection, 'HTTP20Connection', DummyH2Connection) c = HTTPConnection('test', 80) assert isinstance(c._conn, DummyH1Connection) c.request('GET', '/') resp = c.get_response() assert resp == 'h2c' assert isinstance(c._conn, DummyH2Connection) assert c._conn._sock == 'totally a non-secure socket'
def test_tls_upgrade(self, monkeypatch): monkeypatch.setattr( hyper.common.connection, 'HTTP11Connection', DummyH1Connection ) monkeypatch.setattr( hyper.common.connection, 'HTTP20Connection', DummyH2Connection ) c = HTTPConnection('test', 443) assert isinstance(c._conn, DummyH1Connection) r = c.request('GET', '/') assert r == 'h2' assert isinstance(c._conn, DummyH2Connection) assert c._conn._sock == 'totally a secure socket'
def test_http_upgrade(self, monkeypatch): monkeypatch.setattr( hyper.common.connection, 'HTTP11Connection', DummyH1Connection ) monkeypatch.setattr( hyper.common.connection, 'HTTP20Connection', DummyH2Connection ) c = HTTPConnection('test', 80) assert isinstance(c._conn, DummyH1Connection) c.request('GET', '/') resp = c.get_response() assert resp == 'h2c' assert isinstance(c._conn, DummyH2Connection) assert c._conn._sock == 'totally a non-secure socket'
def test_HTTPConnection_with_custom_context(self): context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.set_default_verify_paths() context.verify_mode = ssl.CERT_REQUIRED context.check_hostname = True context.set_npn_protocols(['h2', 'h2-15']) context.options |= ssl.OP_NO_COMPRESSION conn = HTTPConnection('http2bin.org', 443, ssl_context=context) assert conn.ssl_context.check_hostname assert conn.ssl_context.verify_mode == ssl.CERT_REQUIRED assert conn.ssl_context.options & ssl.OP_NO_COMPRESSION != 0
def test_h1_kwargs(self): c = HTTPConnection( 'test', 443, secure=False, window_manager=True, enable_push=True, ssl_context=False, proxy_host=False, proxy_port=False, other_kwarg=True ) assert c._h1_kwargs == { 'secure': False, 'ssl_context': False, 'proxy_host': False, 'proxy_port': False, 'other_kwarg': True, }
def get_connection(self, host, port, scheme): """ Gets an appropriate HTTP/2 connection object based on host/port/scheme tuples. """ secure = (scheme == 'https') if port is None: # pragma: no cover port = 80 if not secure else 443 try: conn = self.connections[(host, port, scheme)] except KeyError: conn = HTTPConnection(host, port, secure=secure) self.connections[(host, port, scheme)] = conn return conn
def get_connection(self, host, port, scheme, cert=None): """ Gets an appropriate HTTP/2 connection object based on host/port/scheme/cert tuples. """ secure = (scheme == 'https') if port is None: # pragma: no cover port = 80 if not secure else 443 ssl_context = None if cert is not None: ssl_context = init_context(cert=cert) try: conn = self.connections[(host, port, scheme, cert)] except KeyError: conn = HTTPConnection(host, port, secure=secure, ssl_context=ssl_context) self.connections[(host, port, scheme, cert)] = conn return conn