Added CORS headers to load balancer responses
This commit is contained in:
parent
2b8b74f089
commit
b0e0cdc30b
1 changed files with 11 additions and 0 deletions
|
@ -370,6 +370,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
if (H.url.size() == 1){
|
if (H.url.size() == 1){
|
||||||
if (localMode && !conn.isLocal()){
|
if (localMode && !conn.isLocal()){
|
||||||
H.SetBody("Configuration only accessible from local interfaces");
|
H.SetBody("Configuration only accessible from local interfaces");
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("403", "Forbidden", conn);
|
H.SendResponse("403", "Forbidden", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -400,6 +401,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
ret["geo"] = weight_geo;
|
ret["geo"] = weight_geo;
|
||||||
ret["bonus"] = weight_bonus;
|
ret["bonus"] = weight_bonus;
|
||||||
H.SetBody(ret.toString());
|
H.SetBody(ret.toString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -411,6 +413,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
ret[(std::string)hosts[i].name] = stateLookup[hosts[i].state];
|
ret[(std::string)hosts[i].name] = stateLookup[hosts[i].state];
|
||||||
}
|
}
|
||||||
H.SetBody(ret.toPrettyString());
|
H.SetBody(ret.toPrettyString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -426,6 +429,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
H.SetBody(ret.toPrettyString());
|
H.SetBody(ret.toPrettyString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -434,6 +438,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
if (addserver.size()){
|
if (addserver.size()){
|
||||||
if (addserver.size() > 199){
|
if (addserver.size() > 199){
|
||||||
H.SetBody("Host length too long for monitoring");
|
H.SetBody("Host length too long for monitoring");
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -465,6 +470,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
ret[addserver] = stateLookup[newEntry->state];
|
ret[addserver] = stateLookup[newEntry->state];
|
||||||
}
|
}
|
||||||
H.SetBody(ret.toPrettyString());
|
H.SetBody(ret.toPrettyString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -476,6 +482,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
HOST(i).details->fillStreams(ret);
|
HOST(i).details->fillStreams(ret);
|
||||||
}
|
}
|
||||||
H.SetBody(ret.toPrettyString());
|
H.SetBody(ret.toPrettyString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -487,6 +494,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
count += HOST(i).details->getViewers(stream);
|
count += HOST(i).details->getViewers(stream);
|
||||||
}
|
}
|
||||||
H.SetBody(JSON::Value(count).asString());
|
H.SetBody(JSON::Value(count).asString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -519,6 +527,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
INFO_MSG("Winner: %s scores %u", bestHost.c_str(), bestScore);
|
INFO_MSG("Winner: %s scores %u", bestHost.c_str(), bestScore);
|
||||||
}
|
}
|
||||||
H.SetBody(bestHost);
|
H.SetBody(bestHost);
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -539,6 +548,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
H.SetBody(ret.toPrettyString());
|
H.SetBody(ret.toPrettyString());
|
||||||
|
H.setCORSHeaders();
|
||||||
H.SendResponse("200", "OK", conn);
|
H.SendResponse("200", "OK", conn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
continue;
|
continue;
|
||||||
|
@ -573,6 +583,7 @@ int handleRequest(Socket::Connection &conn){
|
||||||
INFO_MSG("Balancing stream %s", stream.c_str());
|
INFO_MSG("Balancing stream %s", stream.c_str());
|
||||||
H.Clean();
|
H.Clean();
|
||||||
H.SetHeader("Content-Type", "text/plain");
|
H.SetHeader("Content-Type", "text/plain");
|
||||||
|
H.setCORSHeaders();
|
||||||
hostEntry *bestHost = 0;
|
hostEntry *bestHost = 0;
|
||||||
unsigned int bestScore = 0;
|
unsigned int bestScore = 0;
|
||||||
for (HOSTLOOP){
|
for (HOSTLOOP){
|
||||||
|
|
Loading…
Add table
Reference in a new issue