Skip to content

Commit cfe52f9

Browse files
authored
Fix InsecureRequestWarning for HTTPS Emscripten requests (#3333)
1 parent 25155d7 commit cfe52f9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

changelog/3331.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed issue where ``InsecureRequestWarning`` was emitted for HTTPS connections when using Emscripten.

src/urllib3/contrib/emscripten/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
self.blocksize = blocksize
6868
self.source_address = None
6969
self.socket_options = None
70+
self.is_verified = False
7071

7172
def set_tunnel(
7273
self,
@@ -228,6 +229,10 @@ def __init__(
228229

229230
self.cert_reqs = None
230231

232+
# The browser will automatically verify all requests.
233+
# We have no control over that setting.
234+
self.is_verified = True
235+
231236
def set_cert(
232237
self,
233238
key_file: str | None = None,

test/contrib/emscripten/test_emscripten.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,28 @@ def count_calls(self, *args, **argv): # type: ignore[no-untyped-def]
947947
assert count == 6
948948

949949
pyodide_test(selenium_coverage, testserver_http.http_host, find_unused_port())
950+
951+
952+
@install_urllib3_wheel()
953+
def test_insecure_requests_warning(
954+
selenium_coverage: typing.Any, testserver_http: PyodideServerInfo
955+
) -> None:
956+
@run_in_pyodide # type: ignore[misc]
957+
def pyodide_test(selenium_coverage, host: str, port: int, https_port: int) -> None: # type: ignore[no-untyped-def]
958+
import warnings
959+
960+
import urllib3
961+
import urllib3.exceptions
962+
963+
http = urllib3.PoolManager()
964+
965+
with warnings.catch_warnings(record=True) as w:
966+
http.request("GET", f"https://{host}:{https_port}")
967+
assert len(w) == 0
968+
969+
pyodide_test(
970+
selenium_coverage,
971+
testserver_http.http_host,
972+
testserver_http.http_port,
973+
testserver_http.https_port,
974+
)

0 commit comments

Comments
 (0)