-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpServer.h
More file actions
122 lines (94 loc) · 1.84 KB
/
Copy pathHttpServer.h
File metadata and controls
122 lines (94 loc) · 1.84 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef _HttpServer_H_
#define _HttpServer_H_
#include <iostream>
#include "servant/Application.h"
#include "globe.h"
using namespace tars;
class HttpRequest : public TC_HttpRequest, public TC_HandleBase
{
public:
HttpRequest()
{
}
virtual ~HttpRequest()
{
}
};
/**
*
*/
class HttpResponse : public TC_HttpResponse, public TC_HandleBase
{
public:
HttpResponse()
{
}
virtual ~HttpResponse()
{
}
};
//
typedef TC_AutoPtr<HttpRequest> HttpRequestPtr;
typedef TC_AutoPtr<HttpResponse> HttpResponsePtr;
/**
*
**/
class HttpServer : public Application
{
public:
/**
*
**/
HttpServer()
{
}
/**
*
**/
virtual ~HttpServer()
{
}
/**
*
**/
virtual void initialize();
/**
*
**/
virtual void destroyApp();
public:
/*
* 加载服务配置
*/
virtual void loadConfig();
/*
* 配置变更,重新加载配置
*/
bool reloadSvrConfig(const string &command, const string ¶ms, string &result);
public:
/**
* 请求ip
*/
string getClientIP(tars::TarsCurrentPtr current, TC_HttpRequest &req);
/**
* 允许跨域请求
*/
void allowCrow(TarsCurrentPtr current, TC_HttpRequest &req);
/**
* 404、500错误处理
*/
void sendErrorPage(tars::TarsCurrentPtr current, TC_HttpRequest &req, int status);
/**
* 应答处理
*/
void sendHttpResponse(tars::TarsCurrentPtr current, TC_HttpRequest &req, TC_HttpResponse &rsp);
private:
//保持连接标志
volatile bool m_bKeepAlive;
//打印日志标记
volatile bool m_bAccessLog;
};
////
extern HttpServer g_app;
////////////////////////////////////////////
#endif