simplified, deny other HTTP methods besides GET, set HTTP headers

This commit is contained in:
john30
2015-05-01 09:25:16 +02:00
parent 7e98f485e1
commit 830e789ce7
+6 -4
View File
@@ -158,7 +158,9 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
if (isHttp) {
if (strcmp(str, "GET") == 0)
return executeGet(args);
} else {
return "HTTP/1.0 405 Method Not Allowed\r\n\r\n";
}
if (args.size() == 2) {
// check for "CMD -h"
if (strcasecmp(args[1].c_str(), "-h") == 0 || strcasecmp(args[1].c_str(), "-?") == 0 || strcasecmp(args[1].c_str(), "--help") == 0)
@@ -196,7 +198,6 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
return executeQuit(args, connected);
if (strcasecmp(str, "H") == 0 || strcasecmp(str, "HELP") == 0)
return executeHelp();
}
return "ERR: command not found";
}
@@ -762,7 +763,7 @@ string MainLoop::executeHelp()
string MainLoop::executeGet(vector<string> &args)
{
size_t argPos = 1;
bool onlyWithData = true;
bool onlyWithData = false;
deque<Message*> messages;
if (args.size() >= argPos+2)
@@ -819,7 +820,8 @@ string MainLoop::executeGet(vector<string> &args)
result.str("");
result.clear();
result << "HTTP/1.0 200 OK\r\n";
result << "Content-Type: application/json\r\n";
result << "Content-Type: application/json;charset=utf-8\r\n";
result << "Access-Control-Allow-Origin: *\r\n";
result << "Content-Length: " << setw(0) << dec << static_cast<unsigned>(str.length()) << "\r\n";
result << "\r\n";
result << str;