add notify and change header name
This commit is contained in:
parent
dfc98e5f3a
commit
ea122f4c9a
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user