UniSet 2.32.1
HttpResolver.h
1/*
2 * Copyright (c) 2020 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// --------------------------------------------------------------------------
20// --------------------------------------------------------------------------
21#ifndef HttpResolver_H_
22#define HttpResolver_H_
23// --------------------------------------------------------------------------
24#include <Poco/JSON/Object.h>
25#include "UniSetTypes.h"
26#include "DebugStream.h"
27#include "UHttpRequestHandler.h"
28#include "UHttpServer.h"
29#include "IORFile.h"
30// -------------------------------------------------------------------------
31const std::string HTTP_RESOLVER_API_VERSION = "v01";
32// -------------------------------------------------------------------------
33namespace uniset
34{
35 //------------------------------------------------------------------------------------------
73 public Poco::Net::HTTPRequestHandler
74 {
75 public:
76 HttpResolver( const std::string& name, int argc, const char* const* argv, const std::string& prefix );
77 virtual ~HttpResolver();
78
80 static std::shared_ptr<HttpResolver> init_resolver( int argc, const char* const* argv, const std::string& prefix = "httpresolver-" );
81
83 static void help_print();
84
85 inline std::shared_ptr<DebugStream> log()
86 {
87 return rlog;
88 }
89
90 virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp ) override;
91
92 void run();
93
94 protected:
95
96 Poco::JSON::Object::Ptr respError( Poco::Net::HTTPServerResponse& resp, Poco::Net::HTTPResponse::HTTPStatus s, const std::string& message );
97 Poco::JSON::Object::Ptr httpGetRequest( const std::string& cmd, const Poco::URI::QueryParameters& p );
98 Poco::JSON::Object::Ptr httpJsonResolve( const std::string& query, const Poco::URI::QueryParameters& p );
99 std::string httpTextResolve( const std::string& query, const Poco::URI::QueryParameters& p );
100
101 std::shared_ptr<Poco::Net::HTTPServer> httpserv;
102 std::string httpHost = { "" };
103 int httpPort = { 8008 };
104 std::string httpCORS_allow = { "*" };
105 std::string httpReplyAddr = { "" };
106
107 std::shared_ptr<DebugStream> rlog;
108 std::string myname;
109
110 std::shared_ptr<IORFile> iorfile;
111
113 public Poco::Net::HTTPRequestHandlerFactory
114 {
115 public:
118
119 virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& req ) override;
120
121 private:
122 HttpResolver* resolver;
123 };
124
125 private:
126 };
127 // ----------------------------------------------------------------------------------
128} // end of namespace uniset
129//------------------------------------------------------------------------------------------
130#endif
Definition HttpResolver.h:74
static std::shared_ptr< HttpResolver > init_resolver(int argc, const char *const *argv, const std::string &prefix="httpresolver-")
Definition HttpResolver.cc:123
static void help_print()
Definition HttpResolver.cc:136
Definition Calibration.h:27