Skip to content

Commit

Permalink
server : allow CORS request with authorization headers (ggerganov#1850)
Browse files Browse the repository at this point in the history
Whisper plugin in Obsidian requires an API key which is
then sent as an authorization header.
However, the presence of an authorization header requires
a CORS Preflight, so both the OPTIONS method and
the Access-Control-Allow-Headers: authorization must be
handled.
  • Loading branch information
valenting authored and jiahansu committed Apr 17, 2024
1 parent 62e8a19 commit 5d017a4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ int main(int argc, char ** argv) {
Server svr;
svr.set_default_headers({{"Server", "whisper.cpp"},
{"Access-Control-Allow-Origin", "*"},
{"Access-Control-Allow-Headers", "content-type"}});
{"Access-Control-Allow-Headers", "content-type, authorization"}});

std::string const default_content = R"(
<html>
Expand Down Expand Up @@ -623,6 +623,9 @@ int main(int argc, char ** argv) {
return false;
});

svr.Options(sparams.request_path + "/inference", [&](const Request &req, Response &res){
});

svr.Post(sparams.request_path + "/inference", [&](const Request &req, Response &res){
// acquire whisper model mutex lock
std::lock_guard<std::mutex> lock(whisper_mutex);
Expand Down

0 comments on commit 5d017a4

Please sign in to comment.