Skip to content

Commit

Permalink
Add CORS headers to dream server to ease integration with third-party…
Browse files Browse the repository at this point in the history
… web interfaces
  • Loading branch information
SebastianAigner committed Sep 4, 2022
1 parent 751283a commit 91e826e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ldm/dream/server.py
Expand Up @@ -16,6 +16,8 @@ class DreamServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
self.send_header("Content-type", "text/html")
self.end_headers()
with open("./static/dream_web/index.html", "rb") as content:
Expand All @@ -33,6 +35,8 @@ def do_GET(self):
elif self.path == "/cancel":
self.canceled.set()
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(bytes('{}', 'utf8'))
Expand All @@ -55,6 +59,8 @@ def do_GET(self):

def do_POST(self):
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
self.send_header("Content-type", "application/json")
self.end_headers()

Expand Down Expand Up @@ -196,6 +202,11 @@ def image_progress(sample, step):
print(f"Canceled.")
return

def do_OPTIONS(self):
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
self.end_headers()

class ThreadingDreamServer(ThreadingHTTPServer):
def __init__(self, server_address):
Expand Down

0 comments on commit 91e826e

Please sign in to comment.