Valentin Gosu commited on
Commit
16a6639
·
unverified ·
1 Parent(s): eea7f53

server : allow CORS request with authorization headers (#1850)

Browse files

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.

Files changed (1) hide show
  1. examples/server/server.cpp +4 -1
examples/server/server.cpp CHANGED
@@ -541,7 +541,7 @@ int main(int argc, char ** argv) {
541
  Server svr;
542
  svr.set_default_headers({{"Server", "whisper.cpp"},
543
  {"Access-Control-Allow-Origin", "*"},
544
- {"Access-Control-Allow-Headers", "content-type"}});
545
 
546
  std::string const default_content = R"(
547
  <html>
@@ -623,6 +623,9 @@ int main(int argc, char ** argv) {
623
  return false;
624
  });
625
 
 
 
 
626
  svr.Post(sparams.request_path + "/inference", [&](const Request &req, Response &res){
627
  // acquire whisper model mutex lock
628
  std::lock_guard<std::mutex> lock(whisper_mutex);
 
541
  Server svr;
542
  svr.set_default_headers({{"Server", "whisper.cpp"},
543
  {"Access-Control-Allow-Origin", "*"},
544
+ {"Access-Control-Allow-Headers", "content-type, authorization"}});
545
 
546
  std::string const default_content = R"(
547
  <html>
 
623
  return false;
624
  });
625
 
626
+ svr.Options(sparams.request_path + "/inference", [&](const Request &req, Response &res){
627
+ });
628
+
629
  svr.Post(sparams.request_path + "/inference", [&](const Request &req, Response &res){
630
  // acquire whisper model mutex lock
631
  std::lock_guard<std::mutex> lock(whisper_mutex);