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
ed661b1c
Commit
ed661b1c
authored
Mar 12, 2022
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改无法删除hls目录的bug:#1485
parent
2d88115b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
20 行删除
+17
-20
3rdpart/ZLToolKit
+1
-1
src/Http/HttpFileManager.cpp
+16
-19
没有找到文件。
ZLToolKit
@
3c4a8ce3
Subproject commit
9d3124047d1ec64bf1674ae71bd4fddd728d2243
Subproject commit
3c4a8ce36a18162b3cdc8094cdeba9d752cb3408
src/Http/HttpFileManager.cpp
查看文件 @
ed661b1c
...
...
@@ -353,35 +353,23 @@ static string pathCat(const string &a, const string &b){
*/
static
void
accessFile
(
TcpSession
&
sender
,
const
Parser
&
parser
,
const
MediaInfo
&
media_info
,
const
string
&
file_path
,
const
HttpFileManager
::
invoker
&
cb
)
{
bool
is_hls
=
end_with
(
file_path
,
kHlsSuffix
);
bool
file_exist
=
File
::
is_file
(
file_path
.
data
());
bool
is_forbid_cache
=
false
;
if
(
!
is_hls
&&
!
file_exist
)
{
if
(
!
is_hls
&&
!
File
::
fileExist
(
file_path
.
data
()))
{
//文件不存在且不是hls,那么直接返回404
sendNotFound
(
cb
);
return
;
}
if
(
is_hls
)
{
//hls,那么移除掉后缀获取真实的stream_id并且修改协议为HLS
//
hls,那么移除掉后缀获取真实的stream_id并且修改协议为HLS
const_cast
<
string
&>
(
media_info
.
_schema
)
=
HLS_SCHEMA
;
replace
(
const_cast
<
string
&>
(
media_info
.
_streamid
),
kHlsSuffix
,
""
);
}
GET_CONFIG_FUNC
(
vector
<
string
>
,
forbidCacheSuffix
,
Http
::
kForbidCacheSuffix
,
[](
const
string
&
str
)
{
return
split
(
str
,
","
);
});
for
(
auto
&
suffix
:
forbidCacheSuffix
)
{
if
(
suffix
!=
""
&&
end_with
(
file_path
,
suffix
)){
is_forbid_cache
=
true
;
break
;
}
}
weak_ptr
<
TcpSession
>
weakSession
=
sender
.
shared_from_this
();
//判断是否有权限访问该文件
canAccessPath
(
sender
,
parser
,
media_info
,
false
,
[
cb
,
file_path
,
parser
,
is_hls
,
is_forbid_cache
,
media_info
,
weakSession
,
file_exist
](
const
string
&
err_msg
,
const
HttpServerCookie
::
Ptr
&
cookie
)
{
canAccessPath
(
sender
,
parser
,
media_info
,
false
,
[
cb
,
file_path
,
parser
,
is_hls
,
media_info
,
weakSession
](
const
string
&
err_msg
,
const
HttpServerCookie
::
Ptr
&
cookie
)
{
auto
strongSession
=
weakSession
.
lock
();
if
(
!
strongSession
)
{
//http客户端已经断开,不需要回复
//
http客户端已经断开,不需要回复
return
;
}
if
(
!
err_msg
.
empty
())
{
...
...
@@ -394,14 +382,13 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
return
;
}
auto
response_file
=
[
file_exist
,
is_hls
,
is_forbid_cache
](
const
HttpServerCookie
::
Ptr
&
cookie
,
const
HttpFileManager
::
invoker
&
cb
,
const
string
&
file_path
,
const
Parser
&
parser
,
const
string
&
file_content
=
""
)
{
auto
response_file
=
[
is_hls
](
const
HttpServerCookie
::
Ptr
&
cookie
,
const
HttpFileManager
::
invoker
&
cb
,
const
string
&
file_path
,
const
Parser
&
parser
,
const
string
&
file_content
=
""
)
{
StrCaseMap
httpHeader
;
if
(
cookie
)
{
httpHeader
[
"Set-Cookie"
]
=
cookie
->
getCookie
(
cookie
->
getAttach
<
HttpCookieAttachment
>
().
_path
);
}
HttpSession
::
HttpResponseInvoker
invoker
=
[
&
](
int
code
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
{
if
(
cookie
&&
file_exist
)
{
if
(
cookie
&&
body
)
{
auto
&
attach
=
cookie
->
getAttach
<
HttpCookieAttachment
>
();
if
(
attach
.
_hls_data
)
{
attach
.
_hls_data
->
addByteUsage
(
body
->
remainSize
());
...
...
@@ -409,6 +396,16 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
}
cb
(
code
,
HttpFileManager
::
getContentType
(
file_path
.
data
()),
headerOut
,
body
);
};
GET_CONFIG_FUNC
(
vector
<
string
>
,
forbidCacheSuffix
,
Http
::
kForbidCacheSuffix
,
[](
const
string
&
str
)
{
return
split
(
str
,
","
);
});
bool
is_forbid_cache
;
for
(
auto
&
suffix
:
forbidCacheSuffix
)
{
if
(
suffix
!=
""
&&
end_with
(
file_path
,
suffix
))
{
is_forbid_cache
=
true
;
break
;
}
}
invoker
.
responseFile
(
parser
.
getHeader
(),
httpHeader
,
file_content
.
empty
()
?
file_path
:
file_content
,
!
is_hls
&&
!
is_forbid_cache
,
file_content
.
empty
());
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论