Can't disable CORS policy for POST Server handler
HamishHamiltonSmith opened this issue · 1 comments
This is probably going to end up being a silly question, but whist being successful in setting the response Access-Control-Allow-Origin
header to *
for a GET request handler, I am unable to disable CORS within a Post handler. I set the same response header and received the following error when attempting a post request to the server with AJAX:
Response to preflight request doesn't pass access control check: It does not have HTTP ok status
Following from this I attempted to set the same header for the httlib::Request
parameter of my lambda in case that was the issue - whilst httplib::Request::set_header
did appear to be valid I got a warning, and even after suppressing it the original error persisted:
server.cpp: In lambda function: server.cpp:8:51: error: passing 'const httplib::Request' as 'this' argument discards qualifiers [-fpermissive] 8 | req.set_header("Access-Control-Allow-Origin", "*");
It would be greatly appreciated if someone could tell me what I'm doing wrong...
Ah I just needed to add a preflight handler to the server - all good.