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
eb89a3e5
Commit
eb89a3e5
authored
Dec 24, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善http服务器对不固定长度body的支持
parent
40c23269
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
13 行增加
和
15 行删除
+13
-15
src/Http/HttpBody.h
+2
-2
src/Http/HttpSession.cpp
+10
-12
src/Http/HttpSession.h
+1
-1
没有找到文件。
src/Http/HttpBody.h
查看文件 @
eb89a3e5
...
...
@@ -52,14 +52,14 @@ public:
virtual
~
HttpBody
(){}
/**
* 剩余数据大小
* 剩余数据大小
,如果返回>=INT64_MAX, 那么就不设置content-length
*/
virtual
uint64_t
remainSize
()
{
return
0
;};
/**
* 读取一定字节数,返回大小可能小于size
* @param size 请求大小
* @return 字节对象
* @return 字节对象
,如果读完了,那么请返回nullptr
*/
virtual
Buffer
::
Ptr
readData
(
uint32_t
size
)
{
return
nullptr
;};
};
...
...
src/Http/HttpSession.cpp
查看文件 @
eb89a3e5
...
...
@@ -156,7 +156,7 @@ bool HttpSession::checkWebSocket(){
auto
res_cb
=
[
this
,
headerOut
](){
_flv_over_websocket
=
true
;
sendResponse
(
"101 Switching Protocols"
,
false
,
nullptr
,
headerOut
,
nullptr
,
fals
e
);
sendResponse
(
"101 Switching Protocols"
,
false
,
nullptr
,
headerOut
,
nullptr
,
tru
e
);
};
//判断是否为websocket-flv
...
...
@@ -219,7 +219,7 @@ bool HttpSession::checkLiveFlvStream(const function<void()> &cb){
if
(
!
cb
)
{
//找到rtmp源,发送http头,负载后续发送
sendResponse
(
"200 OK"
,
false
,
"video/x-flv"
,
KeyValue
(),
nullptr
,
fals
e
);
sendResponse
(
"200 OK"
,
false
,
"video/x-flv"
,
KeyValue
(),
nullptr
,
tru
e
);
}
else
{
cb
();
}
...
...
@@ -313,7 +313,7 @@ void HttpSession::sendResponse(const char *pcStatus,
const
char
*
pcContentType
,
const
HttpSession
::
KeyValue
&
header
,
const
HttpBody
::
Ptr
&
body
,
bool
set_content_len
){
bool
is_http_flv
){
GET_CONFIG
(
string
,
charSet
,
Http
::
kCharSet
);
GET_CONFIG
(
uint32_t
,
keepAliveSec
,
Http
::
kKeepAliveSecond
);
...
...
@@ -322,16 +322,14 @@ void HttpSession::sendResponse(const char *pcStatus,
if
(
body
&&
body
->
remainSize
())
{
//有body,获取body大小
size
=
body
->
remainSize
();
if
(
size
>=
INT64_MAX
)
{
//不固定长度的body,那么不设置content-length字段
size
=
-
1
;
}
}
if
(
!
set_content_len
||
size
==
-
1
){
//如果是不定长度body,或者不设置conten-length,
//那么一定是Keep-Alive类型
if
(
is_http_flv
){
//http-flv直播是Keep-Alive类型
bClose
=
false
;
}
else
if
(
size
>=
INT64_MAX
){
//不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断
bClose
=
true
;
}
HttpSession
::
KeyValue
&
headerOut
=
const_cast
<
HttpSession
::
KeyValue
&>
(
header
);
...
...
@@ -348,8 +346,8 @@ void HttpSession::sendResponse(const char *pcStatus,
headerOut
.
emplace
(
"Access-Control-Allow-Credentials"
,
"true"
);
}
if
(
set_content_len
&&
size
>=
0
){
//文件长度为
定值或者
,且不是http-flv强制设置Content-Length
if
(
!
is_http_flv
&&
size
>=
0
&&
size
<
INT64_MAX
){
//文件长度为
固定值
,且不是http-flv强制设置Content-Length
headerOut
[
"Content-Length"
]
=
StrPrinter
<<
size
<<
endl
;
}
...
...
src/Http/HttpSession.h
查看文件 @
eb89a3e5
...
...
@@ -115,7 +115,7 @@ private:
void
sendNotFound
(
bool
bClose
);
void
sendResponse
(
const
char
*
pcStatus
,
bool
bClose
,
const
char
*
pcContentType
=
nullptr
,
const
HttpSession
::
KeyValue
&
header
=
HttpSession
::
KeyValue
(),
const
HttpBody
::
Ptr
&
body
=
nullptr
,
bool
set_content_len
=
tru
e
);
const
HttpBody
::
Ptr
&
body
=
nullptr
,
bool
is_http_flv
=
fals
e
);
//设置socket标志
void
setSocketFlags
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论