mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-03 08:57:32 +08:00
支持获取http反向代理真实客户端ip: #1388
This commit is contained in:
@@ -124,6 +124,7 @@ const string kVirtualPath = HTTP_FIELD "virtualPath";
|
||||
const string kNotFound = HTTP_FIELD "notFound";
|
||||
const string kDirMenu = HTTP_FIELD "dirMenu";
|
||||
const string kForbidCacheSuffix = HTTP_FIELD "forbidCacheSuffix";
|
||||
const string kForwardedIpHeader = HTTP_FIELD "forwarded_ip_header";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kSendBufSize] = 64 * 1024;
|
||||
@@ -150,6 +151,7 @@ static onceToken token([]() {
|
||||
"</html>"
|
||||
<< endl;
|
||||
mINI::Instance()[kForbidCacheSuffix] = "";
|
||||
mINI::Instance()[kForwardedIpHeader] = "";
|
||||
});
|
||||
|
||||
} // namespace Http
|
||||
|
||||
@@ -223,6 +223,8 @@ extern const std::string kNotFound;
|
||||
extern const std::string kDirMenu;
|
||||
// 禁止缓存文件的后缀
|
||||
extern const std::string kForbidCacheSuffix;
|
||||
// 可以把http代理前真实客户端ip放在http头中:https://github.com/ZLMediaKit/ZLMediaKit/issues/1388
|
||||
extern const std::string kForwardedIpHeader;
|
||||
} // namespace Http
|
||||
|
||||
////////////SHELL配置///////////
|
||||
|
||||
@@ -670,6 +670,11 @@ bool HttpSession::emitHttpEvent(bool doInvoke){
|
||||
return consumed;
|
||||
}
|
||||
|
||||
std::string HttpSession::get_peer_ip() {
|
||||
GET_CONFIG(string, forwarded_ip_header, Http::kForwardedIpHeader);
|
||||
return forwarded_ip_header.empty() ? TcpSession::get_peer_ip() : _parser.getHeader()[forwarded_ip_header];
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_POST(ssize_t &content_len) {
|
||||
GET_CONFIG(size_t,maxReqSize,Http::kMaxReqSize);
|
||||
|
||||
|
||||
@@ -97,6 +97,9 @@ protected:
|
||||
*/
|
||||
void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override;
|
||||
|
||||
//重载获取客户端ip
|
||||
std::string get_peer_ip() override;
|
||||
|
||||
private:
|
||||
void Handle_Req_GET(ssize_t &content_len);
|
||||
void Handle_Req_GET_l(ssize_t &content_len, bool sendBody);
|
||||
|
||||
Reference in New Issue
Block a user