diff --git a/src/components/memory.cpp b/src/components/memory.cpp index bdcc549..118b406 100644 --- a/src/components/memory.cpp +++ b/src/components/memory.cpp @@ -36,6 +36,7 @@ bool memory::getRawProcMem(std::string& ret){ if(f.is_open()){ while(std::getline(f, line)){ ret += line; + ret += "\n"; } } else { ret = "Failed to open proc filesystem"; diff --git a/src/routes.cpp b/src/routes.cpp index 87ec0a8..89ed786 100644 --- a/src/routes.cpp +++ b/src/routes.cpp @@ -9,13 +9,19 @@ void setRoutes(crow::SimpleApp& app){ CROW_ROUTE(app, "/proc/meminfo")([](const crow::request& req){ crow::json::wvalue json; + bool status; + std::string accept = req.get_header_value("Accept"); - std::cerr << "Accept: " << req.get_header_value("Accept") << "\n"; + std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower); - if(memory::getProcMem(json)) - return crow::response(200, json.dump()); - else - return crow::response(503, json.dump()); + if(accept == "text/plain"){ + accept.clear(); + status = memory::getRawProcMem(accept); + return crow::response(status ? 200 : 503, accept); + } else { + status = memory::getProcMem(json); + return crow::response(status ? 200 : 503, json.dump()); + } }); CROW_ROUTE(app, "/mem")([]{ diff --git a/src/routes.hpp b/src/routes.hpp index b6d1003..b30ea8b 100644 --- a/src/routes.hpp +++ b/src/routes.hpp @@ -6,6 +6,8 @@ #pragma once +#include +#include #include #include "components/memory.hpp"