diff --git a/src/trs/libs/transaction.hpp b/src/trs/libs/transaction.hpp index 04047f8..c65f0a5 100644 --- a/src/trs/libs/transaction.hpp +++ b/src/trs/libs/transaction.hpp @@ -59,7 +59,7 @@ namespace trs { try { - m_passport.m_func_name = req.get_header_value("x-server-function"); + m_passport.m_func_name = req.get_header_value("TRS-server-function"); if (m_passport.m_func_name.empty()) throw std::invalid_argument{ var::NO_VALID_DATA }; } catch(std::exception& e) @@ -78,7 +78,7 @@ namespace trs { try { - m_passport.m_token = req.get_header_value("x-server-token"); + m_passport.m_token = req.get_header_value("TRS-server-token"); if (m_passport.m_token.empty()) throw std::invalid_argument{ var::NO_VALID_DATA }; } catch(std::exception& e) diff --git a/src/trs/trs.hpp b/src/trs/trs.hpp index 0e11c75..c1c5716 100644 --- a/src/trs/trs.hpp +++ b/src/trs/trs.hpp @@ -19,11 +19,11 @@ namespace trs { - class http : public httplib::Server + class server : public httplib::Server { public: - http() = default; - ~http() = default; + server() = default; + ~server() = default; public: void init(std::string service_name, std::string app_connection, std::string log_connection) @@ -78,7 +78,7 @@ namespace trs { res.set_header("Access-Control-Allow-Origin", "*"); res.set_header("Allow", "POST, HEAD, OPTIONS"); - res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization, X-server-function, X-token-auth"); + res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization, TRS-server-function, TRS-token-auth"); res.set_header("Access-Control-Allow-Methods", "OPTIONS, HEAD, POST"); }); } @@ -112,6 +112,27 @@ namespace trs }); } }; + + class client + { + public: + client(std::string url, std::string token) : m_cli { url }, m_token { token } { } + ~client() = default; + + public: + auto notify(std::string path, std::string key, std::string data) + { + httplib::Headers headers = { + { "X-token-auth", m_token } + }; + + return m_cli.Post(path, headers, httplib::Params{{key, data}}); + } + + private: + httplib::Client m_cli; + std::string m_token; + }; } diff --git a/tests/main.cpp b/tests/main.cpp index 3fb41a9..cb2c1b3 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -26,8 +26,11 @@ namespace worckspaces auto main(int argc, char* args[]) -> int { - trs::http app; - app.init("test service", "app_connection", "log_connection"); - app.registration("healthcheck", worckspaces::inspector, worckspaces::provider); - app.run(); + trs::client cli {"localhost:5000", "token_auth"}; + cli.notify("/","test", "test message"); + + // trs::server srv; + // srv.init("test service", "app_connection", "log_connection"); + // srv.registration("healthcheck", worckspaces::inspector, worckspaces::provider); + // srv.run(); }