Use CORS headers for streaming for MLX Server (#716)

This commit is contained in:
Kristian Muñiz 2024-04-25 10:26:04 -04:00 committed by GitHub
parent 8a265f0d54
commit 109ee2f2f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,17 +82,21 @@ class APIHandler(BaseHTTPRequestHandler):
self.created = int(time.time())
super().__init__(*args, **kwargs)
def _set_completion_headers(self, status_code: int = 200):
self.send_response(status_code)
self.send_header("Content-type", "application/json")
def _set_cors_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "*")
self.send_header("Access-Control-Allow-Headers", "*")
def _set_completion_headers(self, status_code: int = 200):
self.send_response(status_code)
self.send_header("Content-type", "application/json")
self._set_cors_headers()
def _set_stream_headers(self, status_code: int = 200):
self.send_response(status_code)
self.send_header("Content-type", "text/event-stream")
self.send_header("Cache-Control", "no-cache")
self._set_cors_headers()
def do_OPTIONS(self):
self._set_completion_headers(204)