Add basic CORS headers to allow cross-site access.

Add ¨Access-Control-Allow-Origin: *¨ to the HTTP headers of all replies.
This allows use in a cross-origin AJAX situation.

In compliance with the recommendations of section 4.2 of RFC2616, the header
is added before the existing entity headers.
This commit is contained in:
drxzcl 2013-02-13 09:39:45 +01:00 committed by DennisOSRM
parent f7657280b6
commit c6840496c0

View File

@ -139,11 +139,13 @@ Reply Reply::stockReply(Reply::status_type status) {
Reply rep; Reply rep;
rep.status = status; rep.status = status;
rep.content = ToString(status); rep.content = ToString(status);
rep.headers.resize(2); rep.headers.resize(3);
rep.headers[0].name = "Content-Length"; rep.headers[0].name = "Access-Control-Allow-Origin";
rep.headers[0].value = boost::lexical_cast<std::string>(rep.content.size()); rep.headers[0].value = "*";
rep.headers[1].name = "Content-Type"; rep.headers[1].name = "Content-Length";
rep.headers[1].value = "text/html"; rep.headers[1].value = boost::lexical_cast<std::string>(rep.content.size());
rep.headers[2].name = "Content-Type";
rep.headers[2].value = "text/html";
return rep; return rep;
} }
} // namespace http } // namespace http