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
dc672b14
Commit
dc672b14
authored
Feb 10, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
确保32位系统支持超过4GB文件下载
parent
ba213346
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
30 行增加
和
32 行删除
+30
-32
src/Http/HttpBody.cpp
+4
-4
src/Http/HttpBody.h
+7
-7
src/Http/HttpSession.cpp
+19
-21
没有找到文件。
src/Http/HttpBody.cpp
查看文件 @
dc672b14
...
...
@@ -40,7 +40,7 @@ HttpStringBody::HttpStringBody(string str) {
_str
=
std
::
move
(
str
);
}
ssize
_t
HttpStringBody
::
remainSize
()
{
int64
_t
HttpStringBody
::
remainSize
()
{
return
_str
.
size
()
-
_offset
;
}
...
...
@@ -150,7 +150,7 @@ private:
std
::
shared_ptr
<
char
>
_map_addr
;
};
ssize
_t
HttpFileBody
::
remainSize
()
{
int64
_t
HttpFileBody
::
remainSize
()
{
return
_read_to
-
_file_offset
;
}
...
...
@@ -205,7 +205,7 @@ HttpMultiFormBody::HttpMultiFormBody(const HttpArgs &args, const string &filePat
_totalSize
=
_bodyPrefix
.
size
()
+
_bodySuffix
.
size
()
+
_fileBody
->
remainSize
();
}
ssize
_t
HttpMultiFormBody
::
remainSize
()
{
int64
_t
HttpMultiFormBody
::
remainSize
()
{
return
_totalSize
-
_offset
;
}
...
...
@@ -270,7 +270,7 @@ HttpBufferBody::HttpBufferBody(Buffer::Ptr buffer) {
_buffer
=
std
::
move
(
buffer
);
}
ssize
_t
HttpBufferBody
::
remainSize
()
{
int64
_t
HttpBufferBody
::
remainSize
()
{
return
_buffer
?
_buffer
->
size
()
:
0
;
}
...
...
src/Http/HttpBody.h
查看文件 @
dc672b14
...
...
@@ -37,7 +37,7 @@ public:
/**
* 剩余数据大小,如果返回-1, 那么就不设置content-length
*/
virtual
ssize
_t
remainSize
()
{
return
0
;};
virtual
int64
_t
remainSize
()
{
return
0
;};
/**
* 读取一定字节数,返回大小可能小于size
...
...
@@ -77,7 +77,7 @@ public:
HttpStringBody
(
std
::
string
str
);
~
HttpStringBody
()
override
=
default
;
ssize
_t
remainSize
()
override
;
int64
_t
remainSize
()
override
;
toolkit
::
Buffer
::
Ptr
readData
(
size_t
size
)
override
;
private
:
...
...
@@ -94,7 +94,7 @@ public:
HttpBufferBody
(
toolkit
::
Buffer
::
Ptr
buffer
);
~
HttpBufferBody
()
override
=
default
;
ssize
_t
remainSize
()
override
;
int64
_t
remainSize
()
override
;
toolkit
::
Buffer
::
Ptr
readData
(
size_t
size
)
override
;
private
:
...
...
@@ -123,7 +123,7 @@ public:
*/
void
setRange
(
uint64_t
offset
,
uint64_t
max_size
);
ssize
_t
remainSize
()
override
;
int64
_t
remainSize
()
override
;
toolkit
::
Buffer
::
Ptr
readData
(
size_t
size
)
override
;
int
sendFile
(
int
fd
)
override
;
...
...
@@ -152,7 +152,7 @@ public:
*/
HttpMultiFormBody
(
const
HttpArgs
&
args
,
const
std
::
string
&
filePath
,
const
std
::
string
&
boundary
=
"0xKhTmLbOuNdArY"
);
virtual
~
HttpMultiFormBody
(){}
ssize
_t
remainSize
()
override
;
int64
_t
remainSize
()
override
;
toolkit
::
Buffer
::
Ptr
readData
(
size_t
size
)
override
;
public
:
...
...
@@ -161,8 +161,8 @@ public:
static
std
::
string
multiFormContentType
(
const
std
::
string
&
boundary
);
private
:
size
_t
_offset
=
0
;
size
_t
_totalSize
;
uint64
_t
_offset
=
0
;
int64
_t
_totalSize
;
std
::
string
_bodyPrefix
;
std
::
string
_bodySuffix
;
HttpFileBody
::
Ptr
_fileBody
;
...
...
src/Http/HttpSession.cpp
查看文件 @
dc672b14
...
...
@@ -519,16 +519,16 @@ void HttpSession::sendResponse(int code,
GET_CONFIG
(
uint32_t
,
keepAliveSec
,
Http
::
kKeepAliveSecond
);
//body默认为空
ssize
_t
size
=
0
;
int64
_t
size
=
0
;
if
(
body
&&
body
->
remainSize
())
{
//有body,获取body大小
size
=
body
->
remainSize
();
}
if
(
no_content_length
)
{
//http-flv直播是Keep-Alive类型
if
(
no_content_length
)
{
//
http-flv直播是Keep-Alive类型
bClose
=
false
;
}
else
if
((
size_t
)
size
>=
SIZE_MAX
||
size
<
0
)
{
}
else
if
((
size_t
)
size
>=
SIZE_MAX
||
size
<
0
)
{
//不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断
bClose
=
true
;
}
...
...
@@ -537,47 +537,47 @@ void HttpSession::sendResponse(int code,
headerOut
.
emplace
(
kDate
,
dateStr
());
headerOut
.
emplace
(
kServer
,
kServerName
);
headerOut
.
emplace
(
kConnection
,
bClose
?
"close"
:
"keep-alive"
);
if
(
!
bClose
)
{
if
(
!
bClose
)
{
string
keepAliveString
=
"timeout="
;
keepAliveString
+=
to_string
(
keepAliveSec
);
keepAliveString
+=
", max=100"
;
headerOut
.
emplace
(
kKeepAlive
,
std
::
move
(
keepAliveString
));
headerOut
.
emplace
(
kKeepAlive
,
std
::
move
(
keepAliveString
));
}
if
(
!
_origin
.
empty
())
{
if
(
!
_origin
.
empty
())
{
//设置跨域
headerOut
.
emplace
(
kAccessControlAllowOrigin
,
_origin
);
headerOut
.
emplace
(
kAccessControlAllowOrigin
,
_origin
);
headerOut
.
emplace
(
kAccessControlAllowCredentials
,
"true"
);
}
if
(
!
no_content_length
&&
size
>=
0
&&
(
size_t
)
size
<
SIZE_MAX
)
{
if
(
!
no_content_length
&&
size
>=
0
&&
(
size_t
)
size
<
SIZE_MAX
)
{
//文件长度为固定值,且不是http-flv强制设置Content-Length
headerOut
[
kContentLength
]
=
to_string
(
size
);
}
if
(
size
&&
!
pcContentType
)
{
if
(
size
&&
!
pcContentType
)
{
//有body时,设置缺省类型
pcContentType
=
"text/plain"
;
}
if
((
size
||
no_content_length
)
&&
pcContentType
)
{
if
((
size
||
no_content_length
)
&&
pcContentType
)
{
//有body时,设置文件类型
string
strContentType
=
pcContentType
;
strContentType
+=
"; charset="
;
strContentType
+=
charSet
;
headerOut
.
emplace
(
kContentType
,
std
::
move
(
strContentType
));
headerOut
.
emplace
(
kContentType
,
std
::
move
(
strContentType
));
}
//发送http头
string
str
;
str
.
reserve
(
256
);
str
+=
"HTTP/1.1 "
;
str
+=
"HTTP/1.1 "
;
str
+=
to_string
(
code
);
str
+=
' '
;
str
+=
getHttpStatusMessage
(
code
)
;
str
+=
getHttpStatusMessage
(
code
);
str
+=
"
\r\n
"
;
for
(
auto
&
pr
:
header
)
{
str
+=
pr
.
first
;
str
+=
pr
.
first
;
str
+=
": "
;
str
+=
pr
.
second
;
str
+=
"
\r\n
"
;
...
...
@@ -586,16 +586,16 @@ void HttpSession::sendResponse(int code,
SockSender
::
send
(
std
::
move
(
str
));
_ticker
.
resetTime
();
if
(
!
size
)
{
if
(
!
size
)
{
//没有body
if
(
bClose
)
{
if
(
bClose
)
{
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"close connection after send http header completed with status code:"
<<
code
));
}
return
;
}
if
(
typeid
(
*
this
)
==
typeid
(
HttpSession
)
&&
!
body
->
sendFile
(
getSock
()
->
rawFD
()))
{
//http支持sendfile优化
//
http支持sendfile优化
return
;
}
...
...
@@ -607,9 +607,7 @@ void HttpSession::sendResponse(int code,
//发送http body
AsyncSenderData
::
Ptr
data
=
std
::
make_shared
<
AsyncSenderData
>
(
shared_from_this
(),
body
,
bClose
);
getSock
()
->
setOnFlush
([
data
]()
{
return
AsyncSender
::
onSocketFlushed
(
data
);
});
getSock
()
->
setOnFlush
([
data
]()
{
return
AsyncSender
::
onSocketFlushed
(
data
);
});
AsyncSender
::
onSocketFlushed
(
data
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论