I did never use Cross-Origin Resource-Sharing, but from what I read here
https://developer.mozilla.org/en/docs/HTTP/Access_control_CORSI don't think that it is that easy. In particular, if look at the "Preflighted Requests" chapter.
So adding a line like
Access-Control-Allow-Origin: *
to the response header is only half the story. The full protocol is significantly more sophisticated:
http://www.w3.org/TR/cors/We should not add just half of the protocol to the official repository.
If you want to try if adding this single line is sufficient for your particular use case, try the following:
a) Your line numbers do not fit the current code. In civetweb.c, find the function handle_file_request, and add the
green line
(void) mg_printf(conn,
"HTTP/1.1 %d %s\r\n"
"Access-Control-Allow-Origin: *" "Date: %s\r\n"
"Last-Modified: %s\r\n"
"Etag: %s\r\n"
"Content-Type: %.*s\r\n"
"Content-Length: %" INT64_FMT "\r\n"
"Connection: %s\r\n"
"Accept-Ranges: bytes\r\n"
"%s%s\r\n",
conn->status_code, msg, date, lm, etag, (int) mime_vec.len,
mime_vec.ptr, cl, suggest_connection_header(conn), range, encoding);
This single change should be enough for all static files sent by the server (images, javascripts, stylesheets, videos, ..). Forget about directory requests and other changes for the moment.
You need to recompile the code and test it - I did not try it myself.
b) Alternatively it should be possible to sent this header line by using a Lua script to serve the resources. You do not need to change a single line of C code for this, so the pre-buildt binaries at sourceforge should work as well (or probably not, if this requires the next version .. I have to check that .. the current source on github already has all required features, so it should be at least in the next release).
You would have to create a lua resource script (e.g., by modifying resource_script_demo.lua) to sent the page with any header you like.
I think it would be possible to implement the full CORS protocol through a Lua resource script, not just the "half story"
Access-Control-Allow-Origin: * header.