Skip to content

Commit fd4dffd

Browse files
juntyrillia-v
andauthored
Patch VerifiedHTTPSConnection for Emscripten (#3752)
Co-authored-by: Illia Volochii <[email protected]>
1 parent 13f0bfd commit fd4dffd

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

changelog/3752.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed ``urllib3.connection.VerifiedHTTPSConnection`` on Emscripten.

src/urllib3/contrib/emscripten/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ def inject_into_urllib3() -> None:
1414
HTTPSConnectionPool.ConnectionCls = EmscriptenHTTPSConnection
1515
urllib3.connection.HTTPConnection = EmscriptenHTTPConnection # type: ignore[misc,assignment]
1616
urllib3.connection.HTTPSConnection = EmscriptenHTTPSConnection # type: ignore[misc,assignment]
17+
urllib3.connection.VerifiedHTTPSConnection = EmscriptenHTTPSConnection # type: ignore[assignment]

src/urllib3/contrib/emscripten/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class EmscriptenHTTPConnection:
4040
is_verified: bool = False
4141
proxy_is_verified: bool | None = None
4242

43+
response_class: type[BaseHTTPResponse] = EmscriptenHttpResponseWrapper
4344
_response: EmscriptenResponse | None
4445

4546
def __init__(

test/contrib/emscripten/test_emscripten.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,31 @@ def test_timeout_in_worker_streaming(
302302
run_from_server.run_webworker(worker_code)
303303

304304

305+
@pytest.mark.parametrize(
306+
"connection_cls", ["HTTPSConnection", "VerifiedHTTPSConnection"]
307+
)
305308
def test_index_https(
306-
selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
309+
selenium_coverage: typing.Any,
310+
testserver_http: PyodideServerInfo,
311+
connection_cls: str,
307312
) -> None:
308313
@run_in_pyodide # type: ignore[misc]
309-
def pyodide_test(selenium_coverage, host: str, port: int) -> None: # type: ignore[no-untyped-def]
310-
from urllib3.connection import HTTPSConnection
314+
def pyodide_test(selenium_coverage, host: str, port: int, connection_cls: str) -> None: # type: ignore[no-untyped-def]
315+
from urllib3 import connection
311316
from urllib3.response import BaseHTTPResponse
312317

313-
conn = HTTPSConnection(host, port)
318+
conn = getattr(connection, connection_cls)(host, port)
314319
conn.request("GET", f"https://{host}:{port}/")
315320
response = conn.getresponse()
316321
assert isinstance(response, BaseHTTPResponse)
317322
data = response.data
318323
assert data.decode("utf-8") == "Dummy server!"
319324

320325
pyodide_test(
321-
selenium_coverage, testserver_http.http_host, testserver_http.https_port
326+
selenium_coverage,
327+
testserver_http.http_host,
328+
testserver_http.https_port,
329+
connection_cls,
322330
)
323331

324332

0 commit comments

Comments
 (0)