diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp
index fe61d168..44777de5 100644
--- a/lib/http_parser.cpp
+++ b/lib/http_parser.cpp
@@ -32,6 +32,15 @@ void HTTP::Parser::CleanPreserveHeaders() {
vars.clear();
}
+/// Sets the neccesary headers to allow Cross Origin Resource Sharing with all domains.
+void HTTP::Parser::setCORSHeaders(){
+ SetHeader("Access-Control-Allow-Origin", "*");
+ SetHeader("Access-Control-Allow-Methods", "GET, POST");
+ SetHeader("Access-Control-Allow-Headers", "Content-Type, X-Requested-With");
+ SetHeader("Access-Control-Allow-Credentials", "true");
+}
+
+
/// Returns a string containing a valid HTTP 1.0 or 1.1 request, ready for sending.
/// The request is build from internal variables set before this call is made.
/// To be precise, method, url, protocol, headers and body are used.
diff --git a/lib/http_parser.h b/lib/http_parser.h
index f3f89e62..1e740547 100644
--- a/lib/http_parser.h
+++ b/lib/http_parser.h
@@ -21,6 +21,7 @@ namespace HTTP {
std::string getUrl();
void SetHeader(std::string i, std::string v);
void SetHeader(std::string i, long long v);
+ void setCORSHeaders();
void SetVar(std::string i, std::string v);
void SetBody(std::string s);
void SetBody(char * buffer, int len);
diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp
index 2ea8fe6f..d9a883e8 100644
--- a/src/controller/controller_api.cpp
+++ b/src/controller/controller_api.cpp
@@ -558,10 +558,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
}
H.Clean();
H.SetHeader("Content-Type", "text/javascript");
- H.SetHeader("Access-Control-Allow-Origin", "*");
- H.SetHeader("Access-Control-Allow-Methods", "GET, POST");
- H.SetHeader("Access-Control-Allow-Headers", "Content-Type, X-Requested-With");
- H.SetHeader("Access-Control-Allow-Credentials", "true");
+ H.setCORSHeaders();
if (jsonp == ""){
H.SetBody(Response.toString() + "\n\n");
}else{
diff --git a/src/output/output_hls.cpp b/src/output/output_hls.cpp
index 9ae25191..33ea94d9 100644
--- a/src/output/output_hls.cpp
+++ b/src/output/output_hls.cpp
@@ -168,6 +168,7 @@ namespace Mist {
H.Clean();
H.SetHeader("Content-Type", "text/xml");
H.SetHeader("Server", "mistserver/" PACKAGE_VERSION "/" + Util::Config::libver);
+ H.setCORSHeaders();
H.SetBody("