Skip to content

Commit

Permalink
fix: don't overwrite preflight
Browse files Browse the repository at this point in the history
  • Loading branch information
crisog committed Mar 7, 2024
1 parent d93da82 commit d699465
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions litestar/middleware/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ async def wrapped_send(message: Message) -> None:
headers["Access-Control-Allow-Origin"] = origin
headers["Vary"] = "Origin"

if self.config.allow_headers:
# We don't want to overwrite this for preflight requests.
allow_headers = headers.get("Access-Control-Allow-Headers")
if not allow_headers and self.config.allow_headers:
headers["Access-Control-Allow-Headers"] = ", ".join(sorted(set(self.config.allow_headers)))

if self.config.allow_methods:
allow_methods = headers.get("Access-Control-Allow-Methods")
if not allow_methods and self.config.allow_methods:
headers["Access-Control-Allow-Methods"] = ", ".join(sorted(set(self.config.allow_methods)))

await send(message)
Expand Down

0 comments on commit d699465

Please sign in to comment.