add notify and change header name
This commit is contained in:
parent
dfc98e5f3a
commit
ea122f4c9a
@ -59,7 +59,7 @@ namespace trs
|
|||||||
{
|
{
|
||||||
try
|
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 };
|
if (m_passport.m_func_name.empty()) throw std::invalid_argument{ var::NO_VALID_DATA };
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
@ -78,7 +78,7 @@ namespace trs
|
|||||||
{
|
{
|
||||||
try
|
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 };
|
if (m_passport.m_token.empty()) throw std::invalid_argument{ var::NO_VALID_DATA };
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
namespace trs
|
namespace trs
|
||||||
{
|
{
|
||||||
class http : public httplib::Server
|
class server : public httplib::Server
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
http() = default;
|
server() = default;
|
||||||
~http() = default;
|
~server() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(std::string service_name, std::string app_connection, std::string log_connection)
|
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("Access-Control-Allow-Origin", "*");
|
||||||
res.set_header("Allow", "POST, HEAD, OPTIONS");
|
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");
|
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
|
auto main(int argc, char* args[]) -> int
|
||||||
{
|
{
|
||||||
trs::http app;
|
trs::client cli {"localhost:5000", "token_auth"};
|
||||||
app.init("test service", "app_connection", "log_connection");
|
cli.notify("/","test", "test message");
|
||||||
app.registration("healthcheck", worckspaces::inspector, worckspaces::provider);
|
|
||||||
app.run();
|
// 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