From c6840496c0cc60c49d9f5d60589dcc1fbe35ff2a Mon Sep 17 00:00:00 2001 From: drxzcl Date: Wed, 13 Feb 2013 09:39:45 +0100 Subject: [PATCH] Add basic CORS headers to allow cross-site access. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Server/BasicDatastructures.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Server/BasicDatastructures.h b/Server/BasicDatastructures.h index e87656975..71e3ac996 100644 --- a/Server/BasicDatastructures.h +++ b/Server/BasicDatastructures.h @@ -139,11 +139,13 @@ Reply Reply::stockReply(Reply::status_type status) { Reply rep; rep.status = status; rep.content = ToString(status); - rep.headers.resize(2); - rep.headers[0].name = "Content-Length"; - rep.headers[0].value = boost::lexical_cast(rep.content.size()); - rep.headers[1].name = "Content-Type"; - rep.headers[1].value = "text/html"; + rep.headers.resize(3); + rep.headers[0].name = "Access-Control-Allow-Origin"; + rep.headers[0].value = "*"; + rep.headers[1].name = "Content-Length"; + rep.headers[1].value = boost::lexical_cast(rep.content.size()); + rep.headers[2].name = "Content-Type"; + rep.headers[2].value = "text/html"; return rep; } } // namespace http