Skip to content

Commit

Permalink
Ignore headers that trigger unintended CORS preflight requests
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvo committed Mar 30, 2023
1 parent 4ba4054 commit c9805e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyodide_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion pyodide_http/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit c9805e1

Please sign in to comment.