From cf05b63aa30985dcf2bbc311b01ba1c1a948d8d8 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 4 Feb 2018 16:17:18 +0100 Subject: [PATCH] also serve .csv, fix for invalid HTTP requests --- src/ebusd/mainloop.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index e9923a61..c1684208 100755 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -480,6 +480,11 @@ result_t MainLoop::decodeMessage(const string &data, bool isHttp, bool* connecte } if (isHttp) { + if (args.size() < 2) { + *connected = false; + *ostream << "HTTP/1.0 400 Bad Request\r\n\r\n"; + return RESULT_OK; + } const char* str = args.size() > 0 ? args[0].c_str() : ""; if (strcmp(str, "GET") == 0) { return executeGet(args, connected, ostream); @@ -1794,6 +1799,8 @@ result_t MainLoop::executeGet(const vector& args, bool* connected, ostri type = 6; } else if (ext == "yaml") { type = 7; + } else if (ext == "csv") { + type = 8; } } if (type < 0) { @@ -1843,6 +1850,9 @@ result_t MainLoop::formatHttpResult(result_t ret, int type, ostringstream* ostre case 7: *ostream << "application/yaml;charset=utf-8"; break; + case 9: + *ostream << "text/comma-separated-values"; + break; default: *ostream << "text/html"; break;