diff --git a/pyodide_http/__init__.py b/pyodide_http/__init__.py index 029ed23..ba33f93 100644 --- a/pyodide_http/__init__.py +++ b/pyodide_http/__init__.py @@ -5,7 +5,7 @@ except ImportError: _SHOULD_PATCH = False -__version__ = "0.2.0" +__version__ = "0.2.1" def patch_requests(continue_on_import_error: bool = False): diff --git a/pyodide_http/_core.py b/pyodide_http/_core.py index b01c10c..1cb711d 100644 --- a/pyodide_http/_core.py +++ b/pyodide_http/_core.py @@ -8,6 +8,13 @@ from ._streaming import send_streaming_request +""" +There are some headers that trigger unintended CORS preflight requests. +See also https://github.com/koenvo/pyodide-http/issues/22 +""" +HEADERS_TO_IGNORE = ("user-agent",) + + class _RequestError(Exception): def __init__(self, message=None, *, request=None, response=None): self.request = request @@ -108,7 +115,8 @@ def send(request: Request, stream: bool = False) -> Response: xhr.open(request.method, request.url, False) for name, value in request.headers.items(): - xhr.setRequestHeader(name, value) + if name.lower() not in HEADERS_TO_IGNORE: + xhr.setRequestHeader(name, value) xhr.send(to_js(request.body))