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
b4327b9b
Commit
b4327b9b
authored
Oct 20, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取文件大小功能移至zltoolkit
parent
0e0608dc
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
11 行增加
和
27 行删除
+11
-27
3rdpart/ZLToolKit
+1
-1
src/Http/HttpBody.cpp
+8
-23
src/Http/HttpBody.h
+1
-2
src/Http/HttpFileManager.cpp
+1
-1
没有找到文件。
ZLToolKit
@
7923e964
Subproject commit
45cf7795835625d07b4de33b25f151330fccc769
Subproject commit
7923e9646f1779d8ce8f256c7f9c0a5bee69e7d7
src/Http/HttpBody.cpp
查看文件 @
b4327b9b
...
...
@@ -10,6 +10,7 @@
#include "HttpBody.h"
#include "Util/util.h"
#include "Util/File.h"
#include "Util/uv_errno.h"
#include "Util/logger.h"
#include "HttpClient.h"
...
...
@@ -46,14 +47,14 @@ Buffer::Ptr HttpStringBody::readData(size_t size) {
HttpFileBody
::
HttpFileBody
(
const
string
&
filePath
){
std
::
shared_ptr
<
FILE
>
fp
(
fopen
(
filePath
.
data
(),
"rb"
),
[](
FILE
*
fp
)
{
if
(
fp
)
{
if
(
fp
)
{
fclose
(
fp
);
}
});
if
(
!
fp
)
{
init
(
fp
,
0
,
0
);
}
else
{
init
(
fp
,
0
,
HttpMultiFormBody
::
fileSize
(
fp
.
get
()));
if
(
!
fp
)
{
init
(
fp
,
0
,
0
);
}
else
{
init
(
fp
,
0
,
File
::
fileSize
(
fp
.
get
()));
}
}
...
...
@@ -61,15 +62,7 @@ HttpFileBody::HttpFileBody(const std::shared_ptr<FILE> &fp, size_t offset, size_
init
(
fp
,
offset
,
max_size
);
}
#if defined(_WIN32) || defined(_WIN64)
#define fseek64 _fseeki64
#define ftell64 _ftelli64
#else
#define fseek64 fseek
#define ftell64 ftell
#endif
void
HttpFileBody
::
init
(
const
std
::
shared_ptr
<
FILE
>
&
fp
,
size_t
offset
,
size_t
max_size
){
void
HttpFileBody
::
init
(
const
std
::
shared_ptr
<
FILE
>
&
fp
,
size_t
offset
,
size_t
max_size
)
{
_fp
=
fp
;
_max_size
=
max_size
;
#ifdef ENABLE_MMAP
...
...
@@ -169,7 +162,7 @@ HttpMultiFormBody::HttpMultiFormBody(const HttpArgs &args,const string &filePath
if
(
!
fp
){
throw
std
::
invalid_argument
(
StrPrinter
<<
"open file failed:"
<<
filePath
<<
" "
<<
get_uv_errmsg
());
}
_fileBody
=
std
::
make_shared
<
HttpFileBody
>
(
fp
,
0
,
fileSize
(
fp
.
get
()));
_fileBody
=
std
::
make_shared
<
HttpFileBody
>
(
fp
,
0
,
File
::
fileSize
(
fp
.
get
()));
auto
fileName
=
filePath
;
auto
pos
=
filePath
.
rfind
(
'/'
);
...
...
@@ -222,14 +215,6 @@ string HttpMultiFormBody::multiFormBodySuffix(const string &boundary){
return
std
::
move
(
body
);
}
size_t
HttpMultiFormBody
::
fileSize
(
FILE
*
fp
)
{
auto
current
=
ftell64
(
fp
);
fseek64
(
fp
,
0L
,
SEEK_END
);
/* 定位到文件末尾 */
auto
end
=
ftell64
(
fp
);
/* 得到文件大小 */
fseek64
(
fp
,
current
,
SEEK_SET
);
return
end
-
current
;
}
string
HttpMultiFormBody
::
multiFormContentType
(
const
string
&
boundary
){
return
StrPrinter
<<
"multipart/form-data; boundary="
<<
boundary
;
}
...
...
src/Http/HttpBody.h
查看文件 @
b4327b9b
...
...
@@ -108,7 +108,7 @@ public:
* @param offset 相对文件头的偏移量
* @param max_size 最大读取字节数,未判断是否大于文件真实大小
*/
HttpFileBody
(
const
std
::
shared_ptr
<
FILE
>
&
fp
,
size_t
offset
,
size_t
max_size
);
HttpFileBody
(
const
std
::
shared_ptr
<
FILE
>
&
fp
,
size_t
offset
,
size_t
max_size
);
HttpFileBody
(
const
string
&
file_path
);
~
HttpFileBody
()
override
=
default
;
...
...
@@ -149,7 +149,6 @@ public:
public
:
static
string
multiFormBodyPrefix
(
const
HttpArgs
&
args
,
const
string
&
boundary
,
const
string
&
fileName
);
static
string
multiFormBodySuffix
(
const
string
&
boundary
);
static
size_t
fileSize
(
FILE
*
fp
);
static
string
multiFormContentType
(
const
string
&
boundary
);
private
:
...
...
src/Http/HttpFileManager.cpp
查看文件 @
b4327b9b
...
...
@@ -598,7 +598,7 @@ void HttpResponseInvokerImp::responseFile(const StrCaseMap &requestHeader,
auto
&
strRange
=
const_cast
<
StrCaseMap
&>
(
requestHeader
)[
"Range"
];
size_t
iRangeStart
=
0
;
size_t
iRangeEnd
=
0
;
size_t
fileSize
=
HttpMultiFormBody
::
fileSize
(
fp
.
get
());
size_t
fileSize
=
File
::
fileSize
(
fp
.
get
());
int
code
;
if
(
strRange
.
size
()
==
0
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论