Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ds4_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3087,6 +3087,9 @@ static bool http_response(int fd, int code, const char *type, const char *body)
"HTTP/1.1 %d %s\r\n"
"Content-Type: %s\r\n"
"Content-Length: %zu\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"
"Access-Control-Allow-Headers: *\r\n"
"Connection: close\r\n\r\n",
code, reason, type, strlen(body));
bool ok = send_all(fd, h.ptr, h.len) && send_all(fd, body, strlen(body));
Expand All @@ -3112,6 +3115,9 @@ static bool sse_headers(int fd) {
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/event-stream\r\n"
"Cache-Control: no-cache\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"
"Access-Control-Allow-Headers: *\r\n"
"Connection: close\r\n\r\n";
return send_all(fd, h, strlen(h));
}
Expand Down Expand Up @@ -7674,6 +7680,12 @@ static void *client_main(void *arg) {
goto done;
}

if (!strcmp(hr.method, "OPTIONS")) {
http_response(fd, 200, "text/plain", "");
http_request_free(&hr);
goto done;
}

if (!strcmp(hr.method, "GET") && !strcmp(hr.path, "/v1/models")) {
send_models(s, fd);
http_request_free(&hr);
Expand Down