simplified, deny other HTTP methods besides GET, set HTTP headers
This commit is contained in:
@@ -158,7 +158,9 @@ string MainLoop::decodeMessage(const string& data, const bool isHttp, bool& conn
|
|||||||
if (isHttp) {
|
if (isHttp) {
|
||||||
if (strcmp(str, "GET") == 0)
|
if (strcmp(str, "GET") == 0)
|
||||||
return executeGet(args);
|
return executeGet(args);
|
||||||
} else {
|
return "HTTP/1.0 405 Method Not Allowed\r\n\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (args.size() == 2) {
|
if (args.size() == 2) {
|
||||||
// check for "CMD -h"
|
// 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)
|
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);
|
return executeQuit(args, connected);
|
||||||
if (strcasecmp(str, "H") == 0 || strcasecmp(str, "HELP") == 0)
|
if (strcasecmp(str, "H") == 0 || strcasecmp(str, "HELP") == 0)
|
||||||
return executeHelp();
|
return executeHelp();
|
||||||
}
|
|
||||||
return "ERR: command not found";
|
return "ERR: command not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,7 +763,7 @@ string MainLoop::executeHelp()
|
|||||||
string MainLoop::executeGet(vector<string> &args)
|
string MainLoop::executeGet(vector<string> &args)
|
||||||
{
|
{
|
||||||
size_t argPos = 1;
|
size_t argPos = 1;
|
||||||
bool onlyWithData = true;
|
bool onlyWithData = false;
|
||||||
|
|
||||||
deque<Message*> messages;
|
deque<Message*> messages;
|
||||||
if (args.size() >= argPos+2)
|
if (args.size() >= argPos+2)
|
||||||
@@ -819,7 +820,8 @@ string MainLoop::executeGet(vector<string> &args)
|
|||||||
result.str("");
|
result.str("");
|
||||||
result.clear();
|
result.clear();
|
||||||
result << "HTTP/1.0 200 OK\r\n";
|
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 << "Content-Length: " << setw(0) << dec << static_cast<unsigned>(str.length()) << "\r\n";
|
||||||
result << "\r\n";
|
result << "\r\n";
|
||||||
result << str;
|
result << str;
|
||||||
|
|||||||
Reference in New Issue
Block a user