blob: 5f4a118920600ea6bb26cdbd534c25438a9c28ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#pragma once
#include "servlet.h"
#include <library/cpp/http/server/http_ex.h>
#include <library/cpp/getopt/last_getopt.h>
#include <util/generic/string.h>
#include <util/system/types.h>
namespace NYql {
namespace NHttp {
///////////////////////////////////////////////////////////////////////////////
// TServerConfig
///////////////////////////////////////////////////////////////////////////////
struct TBind {
enum {
OnLocal = 0x01,
OnRemote = 0x02,
};
};
class TServerConfig
{
public:
TServerConfig()
: Bind_(0)
, Port_(0)
{
}
inline TServerConfig& Bind(ui32 on) {
Bind_ |= on;
return *this;
}
inline bool IsBind(ui32 on) const {
return Bind_ & on;
}
inline TServerConfig& SetPort(ui16 port) {
Port_ = port;
return *this;
}
inline ui16 GetPort() const {
return Port_;
}
inline TServerConfig& SetAssetsPath(const TString& path) {
AssetsPath_ = path;
return *this;
}
inline const TString& GetAssetsPath() const {
return AssetsPath_;
}
void InitCliOptions(NLastGetopt::TOpts& opts);
void ParseFromCli(NLastGetopt::TOptsParseResult& res);
private:
ui32 Bind_;
ui16 Port_;
TString AssetsPath_;
};
///////////////////////////////////////////////////////////////////////////////
// TServer
///////////////////////////////////////////////////////////////////////////////
class TServer:
public THttpServer, public THttpServer::ICallBack,
private TNonCopyable
{
public:
TServer(const TServerConfig& config);
~TServer();
void RegisterServlet(const TString& path, TAutoPtr<IServlet> sp);
const IServlet* FindServlet(TStringBuf path) const;
TVector<TString> GetUrlMappings() const;
private:
TClientRequest* CreateClient() override final;
private:
TVector<std::pair<TString, IServlet*>> Servlets_;
};
} // namspace NNttp
} // namspace NYql
|