Skip to content

Commit

Permalink
feat: 优化cors相关逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
czasg authored Sep 25, 2024
1 parent 1fc84e0 commit 7a59778
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pywss/handler/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def NewCORSHandler(
allow_origins: tuple = ("*",),
allow_methods: tuple = ("*",),
allow_methods: tuple = ("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"),
allow_headers: tuple = ("*",),
allow_credentials: bool = True,
):
Expand All @@ -16,10 +16,9 @@ def NewCORSHandler(
allowCredentials = "true" if allow_credentials else "false"

def corsHandler(ctx: pywss.Context):
origin = allowOrigins
headerOrigin = ctx.headers.get(HeaderOrigin, "")
if "localhost" in headerOrigin:
origin = headerOrigin
useLocal = "localhost" in headerOrigin
origin = headerOrigin if useLocal else allowOrigins
ctx.set_header(HeaderAccessControlAllowOrigin, origin)
ctx.set_header(HeaderAccessControlAllowMethods, allowMethods)
ctx.set_header(HeaderAccessControlAllowHeaders, allowHeaders)
Expand Down

0 comments on commit 7a59778

Please sign in to comment.