#include <RestEndpoint.hpp>
Definition at line 39 of file RestEndpoint.hpp.
◆ RestEndpoint()
Definition at line 41 of file RestEndpoint.hpp.
48 ,
http_client_{ std::make_shared<Pistache::Http::Client>() }
50 { }
Pistache::Address address_
Pistache::Rest::Description description_
std::shared_ptr< Pistache::Http::Client > http_client_
std::shared_ptr< Pistache::Http::Endpoint > http_endpoint_
Pistache::Http::Mime::MediaType accepted_mime_
std::function< void(const cmdobj_t &, cmdlib::cmd::CommandReply)> command_callback_
◆ createDescription()
void dunedaq::restcmd::RestEndpoint::createDescription |
( |
| ) |
|
|
private |
◆ createRouting()
void RestEndpoint::createRouting |
( |
| ) |
|
|
private |
Definition at line 54 of file RestEndpoint.cpp.
55{
56 using namespace Rest;
58}
Pistache::Rest::Router router_
void handle_route_command(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response)
◆ getHttpClient()
std::shared_ptr< Pistache::Http::Client > dunedaq::restcmd::RestEndpoint::getHttpClient |
( |
| ) |
const |
|
inline |
◆ getPort()
uint16_t dunedaq::restcmd::RestEndpoint::getPort |
( |
| ) |
const |
|
inline |
◆ handle_route_command()
void RestEndpoint::handle_route_command |
( |
const Pistache::Rest::Request & | , |
|
|
Pistache::Http::ResponseWriter | response ) |
|
private |
Definition at line 78 of file RestEndpoint.cpp.
79{
81 auto addr = request.address();
82 auto headers = request.headers();
83 auto ct =
headers.get<Http::Header::ContentType>();
85 auto res =
response.send(Http::Code::Not_Acceptable,
"Not a JSON command!\n");
86 } else {
87 auto ansport =
headers.getRaw(
"X-Answer-Port");
88 auto anshost =
headers.tryGetRaw(
"X-Answer-Host");
89 meta.
data[
"ans-port"] = ansport.value();
90 meta.
data[
"ans-host"] = ( !anshost.isEmpty() ? anshost.get().value() : addr.host() );
92 auto res =
response.send(Http::Code::Accepted,
"Command received\n");
93 }
94}
◆ handleResponseCommand()
Definition at line 96 of file RestEndpoint.cpp.
97{
99 std::ostringstream addrstr;
100 addrstr << meta.
data[
"ans-host"].get<std::string>() <<
":" << meta.data[
"ans-port"].get<std::string>() <<
"/response";
101 meta.data[
"cmdid"] = command.
id;
102 TLOG() <<
"Sending POST request to " << addrstr.str();
103
104 nlohmann::json body_json;
108 [&](Http::Response response) {
110 },
111 [&](std::exception_ptr exc) {
112
113 try{
114 std::rethrow_exception(exc);
115 }
116 catch (const std::exception &e) {
117 TLOG() <<
"Exception thrown by Http::Client::post() call: \"" << e.what() <<
"\"; errno = " << errno;
118 }
119 }
120 );
122}
std::vector< Pistache::Async::Promise< Pistache::Http::Response > > http_client_responses_
void to_json(data_t &j, const Command &obj)
◆ init()
void RestEndpoint::init |
( |
size_t | threads | ) |
|
Definition at line 20 of file RestEndpoint.cpp.
21{
22 auto opts = Http::Endpoint::options()
23 .threads(static_cast<int>(threads))
24 .maxRequestSize(15728640)
25 .maxResponseSize(1048576)
26 .flags(Pistache::Tcp::Options::ReuseAddr)
27 .flags(Pistache::Tcp::Options::ReusePort);
28
33}
Pistache::Http::Client::Options http_client_options_
◆ shutdown()
void RestEndpoint::shutdown |
( |
| ) |
|
◆ start()
void RestEndpoint::start |
( |
| ) |
|
◆ stop()
void dunedaq::restcmd::RestEndpoint::stop |
( |
| ) |
|
◆ accepted_mime_
Pistache::Http::Mime::MediaType dunedaq::restcmd::RestEndpoint::accepted_mime_ |
|
private |
◆ address_
Pistache::Address dunedaq::restcmd::RestEndpoint::address_ |
|
private |
◆ command_callback_
◆ description_
Pistache::Rest::Description dunedaq::restcmd::RestEndpoint::description_ |
|
private |
◆ http_client_
std::shared_ptr<Pistache::Http::Client> dunedaq::restcmd::RestEndpoint::http_client_ |
|
private |
◆ http_client_options_
Pistache::Http::Client::Options dunedaq::restcmd::RestEndpoint::http_client_options_ |
|
private |
◆ http_client_responses_
std::vector<Pistache::Async::Promise<Pistache::Http::Response> > dunedaq::restcmd::RestEndpoint::http_client_responses_ |
|
private |
◆ http_endpoint_
std::shared_ptr<Pistache::Http::Endpoint> dunedaq::restcmd::RestEndpoint::http_endpoint_ |
|
private |
◆ port_
Pistache::Port dunedaq::restcmd::RestEndpoint::port_ |
|
private |
◆ router_
Pistache::Rest::Router dunedaq::restcmd::RestEndpoint::router_ |
|
private |
◆ server_thread_
std::thread dunedaq::restcmd::RestEndpoint::server_thread_ |
|
private |
The documentation for this class was generated from the following files: