Skip to content

Commit 9545965

Browse files
committed
Add CORS headers.
1 parent 9bdb6b5 commit 9545965

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

scripts/jsonrpcproxy.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,41 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
7676
def do_GET(self):
7777
self.send_response(200)
7878
self.send_header("Content-type", "text/plain")
79+
self.addCORS()
7980
self.end_headers()
8081
backend_url = 'unix:' + self.server.backend_address
8182
proxy_url = '{}:{}'.format(self.server.server_name,
8283
self.server.server_port)
8384
info = INFO.format(VERSION, backend_url, proxy_url)
8485
self.wfile.write(info.encode('utf-8'))
8586

87+
def do_OPTIONS(self):
88+
self.send_response(200)
89+
self.send_header("Content-type", "text/plain")
90+
self.addCORS()
91+
self.end_headers()
92+
8693
def do_POST(self):
8794
request_length = int(self.headers['Content-Length'])
8895
request_content = self.rfile.read(request_length)
8996
# self.log_message("Headers: {}".format(self.headers))
90-
self.log_message("Request: {}".format(request_content))
97+
# self.log_message("Request: {}".format(request_content))
9198

9299
response_content = self.server.process(request_content)
93-
self.log_message("Response: {}".format(response_content))
100+
# self.log_message("Response: {}".format(response_content))
94101

95102
self.send_response(200)
96103
self.send_header("Content-type", "application/json")
97104
self.send_header("Content-length", len(response_content))
105+
self.addCORS()
98106
self.end_headers()
99107
self.wfile.write(response_content)
100108

109+
def addCORS(self):
110+
self.send_header("Access-Control-Allow-Origin", "*")
111+
self.send_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
112+
self.send_header("Access-Control-Allow-Headers", "content-type")
113+
101114

102115
class Proxy(HTTPServer):
103116

0 commit comments

Comments
 (0)