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
003021e2
Commit
003021e2
authored
Dec 26, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化http服务器性能
parent
f7db9d36
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
36 行增加
和
16 行删除
+36
-16
src/Http/HttpSession.cpp
+36
-16
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
003021e2
/*
/*
* MIT License
*
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
...
...
@@ -308,6 +308,16 @@ static string dateStr() {
return
buf
;
}
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"
;
static
const
string
kServerName
=
SERVER_NAME
;
void
HttpSession
::
sendResponse
(
const
char
*
pcStatus
,
bool
bClose
,
const
char
*
pcContentType
,
...
...
@@ -333,22 +343,25 @@ void HttpSession::sendResponse(const char *pcStatus,
}
HttpSession
::
KeyValue
&
headerOut
=
const_cast
<
HttpSession
::
KeyValue
&>
(
header
);
headerOut
.
emplace
(
"Date"
,
dateStr
());
headerOut
.
emplace
(
"Server"
,
SERVER_NAME
);
headerOut
.
emplace
(
"Connection"
,
bClose
?
"close"
:
"keep-alive"
);
headerOut
.
emplace
(
kDate
,
dateStr
());
headerOut
.
emplace
(
kServer
,
kServerName
);
headerOut
.
emplace
(
kConnection
,
bClose
?
"close"
:
"keep-alive"
);
if
(
!
bClose
){
headerOut
.
emplace
(
"Keep-Alive"
,
StrPrinter
<<
"timeout="
<<
keepAliveSec
<<
", max=100"
<<
endl
);
string
keepAliveString
=
"timeout="
;
keepAliveString
+=
to_string
(
keepAliveSec
);
keepAliveString
+=
", max=100"
;
headerOut
.
emplace
(
kKeepAlive
,
std
::
move
(
keepAliveString
));
}
if
(
!
_origin
.
empty
()){
//设置跨域
headerOut
.
emplace
(
"Access-Control-Allow-Origin"
,
_origin
);
headerOut
.
emplace
(
"Access-Control-Allow-Credentials"
,
"true"
);
headerOut
.
emplace
(
kAccessControlAllowOrigin
,
_origin
);
headerOut
.
emplace
(
kAccessControlAllowCredentials
,
"true"
);
}
if
(
!
is_http_flv
&&
size
>=
0
&&
size
<
INT64_MAX
){
//文件长度为固定值,且不是http-flv强制设置Content-Length
headerOut
[
"Content-Length"
]
=
StrPrinter
<<
size
<<
endl
;
headerOut
[
kContentLength
]
=
to_string
(
size
)
;
}
if
(
size
&&
!
pcContentType
){
...
...
@@ -358,19 +371,26 @@ void HttpSession::sendResponse(const char *pcStatus,
if
(
size
&&
pcContentType
){
//有body时,设置文件类型
auto
strContentType
=
StrPrinter
<<
pcContentType
<<
"; charset="
<<
charSet
<<
endl
;
headerOut
.
emplace
(
"Content-Type"
,
strContentType
);
string
strContentType
=
pcContentType
;
strContentType
+=
"; charset="
;
strContentType
+=
charSet
;
headerOut
.
emplace
(
kContentType
,
std
::
move
(
strContentType
));
}
//发送http头
_StrPrinter
printer
;
printer
<<
"HTTP/1.1 "
<<
pcStatus
<<
"
\r\n
"
;
string
str
;
str
.
reserve
(
256
);
str
+=
"HTTP/1.1 "
;
str
+=
pcStatus
;
str
+=
"
\r\n
"
;
for
(
auto
&
pr
:
header
)
{
printer
<<
pr
.
first
<<
": "
<<
pr
.
second
<<
"
\r\n
"
;
str
+=
pr
.
first
;
str
+=
": "
;
str
+=
pr
.
second
;
str
+=
"
\r\n
"
;
}
printer
<<
"
\r\n
"
;
send
(
printer
<<
endl
);
str
+=
"
\r\n
"
;
send
(
std
::
move
(
str
));
_ticker
.
resetTime
();
if
(
!
size
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论