UniSet @VERSION@
UHttpServer.h
1#ifndef DISABLE_REST_API
2/*
3 * Copyright (c) 2015 Pavel Vainerman.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation, version 2.1.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Lesser Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17// -------------------------------------------------------------------------
18#ifndef UHttpServer_H_
19#define UHttpServer_H_
20// -------------------------------------------------------------------------
21#include <string>
22#include <memory>
23#include <vector>
24#include <Poco/Net/HTTPServer.h>
25#include "DebugStream.h"
26#include "ThreadCreator.h"
27#include "UHttpRequestHandler.h"
28// -------------------------------------------------------------------------
53// -------------------------------------------------------------------------
54namespace uniset
55{
56 namespace UHttp
57 {
59 {
60 public:
61
62 UHttpServer( std::shared_ptr<IHttpRequestRegistry>& supplier, const std::string& host, int port );
63 virtual ~UHttpServer();
64
65 void start();
66 void stop();
67
68 std::shared_ptr<DebugStream> log();
69
70 // (CORS): Access-Control-Allow-Origin. Default: *
71 void setCORS_allow( const std::string& CORS_allow );
72 void setDefaultContentType( const std::string& ct);
73 void setWhitelist( const std::vector<std::string>& wl );
74 void setBlacklist( const std::vector<std::string>& bl );
75 // Доверенные прокси, от которых принимаем X-Forwarded-For/X-Real-IP
76 void setTrustedProxies( const std::vector<std::string>& proxies );
77 // Bearer auth: включение и список допустимых токенов
78 void setBearerRequired( bool required );
79 void setBearerTokens( const std::vector<std::string>& tokens );
80 protected:
82
83 private:
84
85 std::shared_ptr<DebugStream> mylog;
86 Poco::Net::SocketAddress sa;
87
88 // Note: HTTPServer takes ownership of reqFactory, so we just keep a raw pointer
89 // for configuration methods. HTTPServer will delete it.
90 UHttpRequestHandlerFactory* reqFactory = { nullptr };
91 std::shared_ptr<Poco::Net::HTTPServer> http;
92 UHttp::NetworkRules whitelist;
93 UHttp::NetworkRules blacklist;
94 UHttp::NetworkRules trustedProxies;
95 UHttp::BearerTokens bearerTokens;
96 bool bearerRequired = { false };
97
98 };
99 }
100}
101// -------------------------------------------------------------------------
102#endif // UHttpServer_H_
103// -------------------------------------------------------------------------
104#endif
Definition UHttpRequestHandler.h:216
Definition UHttpServer.h:59
Definition AccessConfig.h:30