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
52c7bc1d
Commit
52c7bc1d
authored
Jun 10, 2023
by
xia-chu
Committed by
夏楚
Jun 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精简HttpServer代码
parent
fff53cf0
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
28 行增加
和
41 行删除
+28
-41
src/Http/HttpConst.cpp
+2
-2
src/Http/HttpConst.h
+18
-12
src/Http/HttpFileManager.cpp
+1
-1
src/Http/HttpSession.cpp
+7
-25
src/Http/HttpSession.h
+0
-1
没有找到文件。
src/Http/HttpConst.cpp
查看文件 @
52c7bc1d
...
...
@@ -18,7 +18,7 @@ using namespace toolkit;
namespace
mediakit
{
const
char
*
getHttpStatusMessage
(
int
status
)
{
const
char
*
HttpConst
::
getHttpStatusMessage
(
int
status
)
{
switch
(
status
)
{
case
100
:
return
"Continue"
;
case
101
:
return
"Switching Protocol"
;
...
...
@@ -196,7 +196,7 @@ static const char *s_mime_src[][2] = {
{
"avi"
,
"video/x-msvideo"
},
};
const
string
&
getHttpContentType
(
const
char
*
name
)
{
const
string
&
HttpConst
::
getHttpContentType
(
const
char
*
name
)
{
const
char
*
dot
;
dot
=
strrchr
(
name
,
'.'
);
static
StrCaseMap
mapType
;
...
...
src/Http/HttpConst.h
查看文件 @
52c7bc1d
...
...
@@ -15,19 +15,25 @@
namespace
mediakit
{
/**
* 根据http错误代码获取字符说明
* @param status 譬如404
* @return 错误代码字符说明,譬如Not Found
*/
const
char
*
getHttpStatusMessage
(
int
status
);
class
HttpConst
{
public
:
HttpConst
()
=
delete
;
~
HttpConst
()
=
delete
;
/**
* 根据文件后缀返回http mime
* @param name 文件后缀,譬如html
* @return mime值,譬如text/html
*/
const
std
::
string
&
getHttpContentType
(
const
char
*
name
);
/**
* 根据http错误代码获取字符说明
* @param status 譬如404
* @return 错误代码字符说明,譬如Not Found
*/
static
const
char
*
getHttpStatusMessage
(
int
status
);
/**
* 根据文件后缀返回http mime
* @param name 文件后缀,譬如html
* @return mime值,譬如text/html
*/
static
const
std
::
string
&
getHttpContentType
(
const
char
*
name
);
};
}
//mediakit
...
...
src/Http/HttpFileManager.cpp
查看文件 @
52c7bc1d
...
...
@@ -46,7 +46,7 @@ struct HttpCookieAttachment {
};
const
string
&
HttpFileManager
::
getContentType
(
const
char
*
name
)
{
return
getHttpContentType
(
name
);
return
HttpConst
::
getHttpContentType
(
name
);
}
static
string
searchIndexFile
(
const
string
&
dir
){
...
...
src/Http/HttpSession.cpp
查看文件 @
52c7bc1d
...
...
@@ -75,9 +75,6 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
return
0
;
}
// 跨域
_origin
=
_parser
[
"Origin"
];
//默认后面数据不是content而是header
ssize_t
content_len
=
0
;
(
this
->*
(
it
->
second
))(
content_len
);
...
...
@@ -507,15 +504,6 @@ private:
}
};
static
const
string
kDate
=
"Date"
;
static
const
string
kServer
=
"Server"
;
static
const
string
kConnection
=
"Connection"
;
static
const
string
kKeepAlive
=
"Keep-Alive"
;
static
const
string
kContentType
=
"Content-Type"
;
static
const
string
kContentLength
=
"Content-Length"
;
static
const
string
kAccessControlAllowOrigin
=
"Access-Control-Allow-Origin"
;
static
const
string
kAccessControlAllowCredentials
=
"Access-Control-Allow-Credentials"
;
void
HttpSession
::
sendResponse
(
int
code
,
bool
bClose
,
const
char
*
pcContentType
,
...
...
@@ -541,25 +529,19 @@ void HttpSession::sendResponse(int code,
}
HttpSession
::
KeyValue
&
headerOut
=
const_cast
<
HttpSession
::
KeyValue
&>
(
header
);
headerOut
.
emplace
(
kDate
,
dateStr
());
headerOut
.
emplace
(
kServer
,
kServerName
);
headerOut
.
emplace
(
kConnection
,
bClose
?
"close"
:
"keep-alive"
);
headerOut
.
emplace
(
"Date"
,
dateStr
());
headerOut
.
emplace
(
"Server"
,
kServerName
);
headerOut
.
emplace
(
"Connection"
,
bClose
?
"close"
:
"keep-alive"
);
if
(
!
bClose
)
{
string
keepAliveString
=
"timeout="
;
keepAliveString
+=
to_string
(
keepAliveSec
);
keepAliveString
+=
", max=100"
;
headerOut
.
emplace
(
kKeepAlive
,
std
::
move
(
keepAliveString
));
}
if
(
!
_origin
.
empty
())
{
// 设置跨域
headerOut
.
emplace
(
kAccessControlAllowOrigin
,
_origin
);
headerOut
.
emplace
(
kAccessControlAllowCredentials
,
"true"
);
headerOut
.
emplace
(
"Keep-Alive"
,
std
::
move
(
keepAliveString
));
}
if
(
!
no_content_length
&&
size
>=
0
&&
(
size_t
)
size
<
SIZE_MAX
)
{
// 文件长度为固定值,且不是http-flv强制设置Content-Length
headerOut
[
kContentLength
]
=
to_string
(
size
);
headerOut
[
"Content-Length"
]
=
to_string
(
size
);
}
if
(
size
&&
!
pcContentType
)
{
...
...
@@ -572,7 +554,7 @@ void HttpSession::sendResponse(int code,
string
strContentType
=
pcContentType
;
strContentType
+=
"; charset="
;
strContentType
+=
charSet
;
headerOut
.
emplace
(
kContentType
,
std
::
move
(
strContentType
));
headerOut
.
emplace
(
"Content-Type"
,
std
::
move
(
strContentType
));
}
// 发送http头
...
...
@@ -581,7 +563,7 @@ void HttpSession::sendResponse(int code,
str
+=
"HTTP/1.1 "
;
str
+=
to_string
(
code
);
str
+=
' '
;
str
+=
getHttpStatusMessage
(
code
);
str
+=
HttpConst
::
getHttpStatusMessage
(
code
);
str
+=
"
\r\n
"
;
for
(
auto
&
pr
:
header
)
{
str
+=
pr
.
first
;
...
...
src/Http/HttpSession.h
查看文件 @
52c7bc1d
...
...
@@ -132,7 +132,6 @@ private:
bool
_live_over_websocket
=
false
;
//消耗的总流量
uint64_t
_total_bytes_usage
=
0
;
std
::
string
_origin
;
Parser
_parser
;
toolkit
::
Ticker
_ticker
;
TSMediaSource
::
RingType
::
RingReader
::
Ptr
_ts_reader
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论