Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
4c398216
Commit
4c398216
authored
May 16, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加http服务器配置项:是否支持vhost
parent
36e8dcfa
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
19 行增加
和
13 行删除
+19
-13
3rdpart/ZLToolKit
+1
-1
src/Common/config.cpp
+5
-0
src/Common/config.h
+2
-0
src/Http/HttpSession.cpp
+11
-10
src/Http/HttpSession.h
+0
-2
没有找到文件。
ZLToolKit
@
02c344ef
Subproject commit
b38a866916d166fba8a33275b9375f185fcf3671
Subproject commit
02c344efb0eba8bd4f1eec8fb5dce3db5bda284a
src/Common/config.cpp
查看文件 @
4c398216
...
...
@@ -93,6 +93,10 @@ const char kKeepAliveSecond[] = HTTP_FIELD"keepAliveSecond";
#define HTTP_MAX_REQ_CNT 100
const
char
kMaxReqCount
[]
=
HTTP_FIELD
"maxReqCount"
;
//文件服务器是否启动虚拟主机
const
char
kEnableVhost
[]
=
HTTP_FIELD
"enableVhost"
;
//http 字符编码
#if defined(_WIN32)
#define HTTP_CHAR_SET "gb2312"
...
...
@@ -126,6 +130,7 @@ onceToken token([](){
mINI
::
Instance
()[
kCharSet
]
=
HTTP_CHAR_SET
;
mINI
::
Instance
()[
kRootPath
]
=
HTTP_ROOT_PATH
;
mINI
::
Instance
()[
kNotFound
]
=
HTTP_NOT_FOUND
;
mINI
::
Instance
()[
kEnableVhost
]
=
1
;
},
nullptr
);
}
//namespace Http
...
...
src/Common/config.h
查看文件 @
4c398216
...
...
@@ -165,6 +165,8 @@ extern const char kCharSet[];
extern
const
char
kRootPath
[];
//http 404错误提示内容
extern
const
char
kNotFound
[];
//文件服务器是否启动虚拟主机
extern
const
char
kEnableVhost
[];
}
//namespace Http
...
...
src/Http/HttpSession.cpp
查看文件 @
4c398216
...
...
@@ -105,9 +105,6 @@ HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
pSock
->
setSendTimeOutSecond
(
15
);
//起始接收buffer缓存设置为4K,节省内存
pSock
->
setReadBuffer
(
std
::
make_shared
<
BufferRaw
>
(
4
*
1024
));
GET_CONFIG_AND_REGISTER
(
string
,
rootPath
,
Http
::
kRootPath
);
_strPath
=
rootPath
;
}
HttpSession
::~
HttpSession
()
{
...
...
@@ -266,6 +263,9 @@ inline bool HttpSession::checkLiveFlvStream(){
}
return
true
;
}
inline
bool
makeMeun
(
const
string
&
httpPath
,
const
string
&
strFullPath
,
const
string
&
vhost
,
string
&
strRet
)
;
inline
bool
HttpSession
::
Handle_Req_GET
(
int64_t
&
content_len
)
{
//先看看是否为WebSocket请求
if
(
checkWebSocket
()){
...
...
@@ -293,16 +293,19 @@ inline bool HttpSession::Handle_Req_GET(int64_t &content_len) {
auto
fullUrl
=
string
(
HTTP_SCHEMA
)
+
"://"
+
_parser
[
"Host"
]
+
_parser
.
FullUrl
();
_mediaInfo
.
parse
(
fullUrl
);
string
strFile
=
_strPath
+
"/"
+
_mediaInfo
.
_vhost
+
_parser
.
Url
();
/////////////HTTP连接是否需要被关闭////////////////
GET_CONFIG_AND_REGISTER
(
uint32_t
,
reqCnt
,
Http
::
kMaxReqCount
);
GET_CONFIG_AND_REGISTER
(
bool
,
enableVhost
,
Http
::
kEnableVhost
);
GET_CONFIG_AND_REGISTER
(
string
,
rootPath
,
Http
::
kRootPath
);
string
strFile
=
enableVhost
?
rootPath
+
"/"
+
_mediaInfo
.
_vhost
+
_parser
.
Url
()
:
rootPath
+
_parser
.
Url
();
replace
(
strFile
,
"//"
,
"/"
);
bool
bClose
=
(
strcasecmp
(
_parser
[
"Connection"
].
data
(),
"close"
)
==
0
)
||
(
++
_iReqCnt
>
reqCnt
);
//访问的是文件夹
if
(
strFile
.
back
()
==
'/'
||
File
::
is_dir
(
strFile
.
data
()))
{
//生成文件夹菜单索引
string
strMeun
;
if
(
!
makeMeun
(
strFile
,
_mediaInfo
.
_vhost
,
strMeun
))
{
if
(
!
makeMeun
(
_parser
.
Url
(),
strFile
,
_mediaInfo
.
_vhost
,
strMeun
))
{
//文件夹不存在
sendNotFound
(
bClose
);
return
!
bClose
;
...
...
@@ -432,7 +435,7 @@ inline bool HttpSession::Handle_Req_GET(int64_t &content_len) {
return
true
;
}
inline
bool
HttpSession
::
makeMeun
(
const
string
&
strFullPath
,
const
string
&
vhost
,
string
&
strRet
)
{
inline
bool
makeMeun
(
const
string
&
httpPath
,
const
string
&
strFullPath
,
const
string
&
vhost
,
string
&
strRet
)
{
string
strPathPrefix
(
strFullPath
);
string
last_dir_name
;
if
(
strPathPrefix
.
back
()
==
'/'
){
...
...
@@ -452,11 +455,9 @@ inline bool HttpSession::makeMeun(const string &strFullPath,const string &vhost,
"<body>
\r\n
"
"<h1>文件索引:"
;
string
strPath
=
strFullPath
;
strPath
=
strPath
.
substr
(
_strPath
.
length
()
+
vhost
.
length
()
+
1
);
ss
<<
strPath
;
ss
<<
httpPath
;
ss
<<
"</h1>
\r\n
"
;
if
(
str
Path
!=
"/"
)
{
if
(
http
Path
!=
"/"
)
{
ss
<<
"<li><a href=
\"
"
;
ss
<<
"/"
;
ss
<<
"
\"
>"
;
...
...
src/Http/HttpSession.h
查看文件 @
4c398216
...
...
@@ -97,7 +97,6 @@ protected:
}
private
:
Parser
_parser
;
string
_strPath
;
Ticker
_ticker
;
uint32_t
_iReqCnt
=
0
;
//消耗的总流量
...
...
@@ -113,7 +112,6 @@ private:
inline
bool
checkWebSocket
();
inline
bool
emitHttpEvent
(
bool
doInvoke
);
inline
void
urlDecode
(
Parser
&
parser
);
inline
bool
makeMeun
(
const
string
&
strFullPath
,
const
string
&
vhost
,
string
&
strRet
);
inline
void
sendNotFound
(
bool
bClose
);
inline
void
sendResponse
(
const
char
*
pcStatus
,
const
KeyValue
&
header
,
const
string
&
strContent
);
inline
static
KeyValue
makeHttpHeader
(
bool
bClose
=
false
,
int64_t
iContentSize
=-
1
,
const
char
*
pcContentType
=
"text/html"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论