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
02aba328
Commit
02aba328
authored
7 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持跨域访问
parent
15afeb7f
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
5 行删除
+14
-5
src/Http/HttpSession.cpp
+11
-4
src/Http/HttpSession.h
+3
-1
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
02aba328
...
...
@@ -424,19 +424,20 @@ inline bool HttpSession::emitHttpEvent(bool doInvoke){
///////////////////是否断开本链接///////////////////////
static
uint32_t
reqCnt
=
mINI
::
Instance
()[
Config
::
Http
::
kMaxReqCount
].
as
<
uint32_t
>
();
bool
bClose
=
(
strcasecmp
(
m_parser
[
"Connection"
].
data
(),
"close"
)
==
0
)
&&
(
++
m_iReqCnt
<
reqCnt
);
auto
Origin
=
m_parser
[
"Origin"
];
/////////////////////异步回复Invoker///////////////////////////////
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
HttpResponseInvoker
invoker
=
[
weakSelf
,
bClose
](
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
){
HttpResponseInvoker
invoker
=
[
weakSelf
,
bClose
,
Origin
](
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
){
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
;
}
strongSelf
->
async
([
weakSelf
,
bClose
,
codeOut
,
headerOut
,
contentOut
]()
{
strongSelf
->
async
([
weakSelf
,
bClose
,
codeOut
,
headerOut
,
contentOut
,
Origin
]()
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
)
{
return
;
}
strongSelf
->
responseDelay
(
bClose
,
codeOut
,
headerOut
,
contentOut
);
strongSelf
->
responseDelay
(
Origin
,
bClose
,
codeOut
,
headerOut
,
contentOut
);
if
(
bClose
){
strongSelf
->
shutdown
();
}
...
...
@@ -463,12 +464,18 @@ inline HttpSession::HttpCode HttpSession::Handle_Req_POST() {
emitHttpEvent
(
true
);
return
Http_success
;
}
void
HttpSession
::
responseDelay
(
bool
bClose
,
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
){
void
HttpSession
::
responseDelay
(
const
string
&
Origin
,
bool
bClose
,
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
){
if
(
codeOut
.
empty
()){
sendNotFound
(
bClose
);
return
;
}
auto
headerOther
=
makeHttpHeader
(
bClose
,
contentOut
.
size
(),
"text/plain"
);
if
(
!
Origin
.
empty
()){
headerOther
[
"Access-Control-Allow-Origin"
]
=
Origin
;
headerOther
[
"Access-Control-Allow-Credentials"
]
=
"true"
;
}
const_cast
<
KeyValue
&>
(
headerOut
).
insert
(
headerOther
.
begin
(),
headerOther
.
end
());
sendResponse
(
codeOut
.
data
(),
headerOut
,
contentOut
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Http/HttpSession.h
查看文件 @
02aba328
...
...
@@ -81,7 +81,9 @@ private:
inline
void
sendNotFound
(
bool
bClose
);
inline
void
sendResponse
(
const
char
*
pcStatus
,
const
KeyValue
&
header
,
const
string
&
strContent
);
inline
static
KeyValue
makeHttpHeader
(
bool
bClose
=
false
,
int64_t
iContentSize
=-
1
,
const
char
*
pcContentType
=
"text/html"
);
void
responseDelay
(
bool
bClose
,
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
);
void
responseDelay
(
const
string
&
Origin
,
bool
bClose
,
const
string
&
codeOut
,
const
KeyValue
&
headerOut
,
const
string
&
contentOut
);
};
}
/* namespace Http */
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论