Add allowed-origins to the server (#987)

This commit is contained in:
Ryo Ota
2026-03-14 11:22:23 +09:00
committed by GitHub
parent 480934402d
commit 332d94ca6f
2 changed files with 14 additions and 1 deletions
+13 -1
View File
@@ -1127,7 +1127,13 @@ class APIHandler(BaseHTTPRequestHandler):
super().__init__(*args, **kwargs)
def _set_cors_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
allowed_origins = self.response_generator.cli_args.allowed_origins
origin = self.headers.get("Origin")
if "*" in allowed_origins:
self.send_header("Access-Control-Allow-Origin", "*")
elif origin in allowed_origins:
self.send_header("Access-Control-Allow-Origin", origin)
self.send_header("Vary", "Origin")
self.send_header("Access-Control-Allow-Methods", "*")
self.send_header("Access-Control-Allow-Headers", "*")
@@ -1895,6 +1901,12 @@ def main():
default=8080,
help="Port for the HTTP server (default: 8080)",
)
parser.add_argument(
"--allowed-origins",
type=lambda x: x.split(","),
default="*",
help="Allowed origins (default: *)",
)
parser.add_argument(
"--draft-model",
type=str,
+1
View File
@@ -47,6 +47,7 @@ class DummyModelProvider:
"prompt_cache_size": 10,
"prompt_cache_bytes": 1 << 63,
"prompt_cache_total_bytes": None,
"allowed_origins": ["*"],
},
)