mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
修复http连接关闭时机的问题
This commit is contained in:
parent
c1f9dc1040
commit
0beb76cc3f
@ -614,6 +614,10 @@ inline bool HttpSession::emitHttpEvent(bool doInvoke){
|
|||||||
if(!consumed && doInvoke){
|
if(!consumed && doInvoke){
|
||||||
//该事件无人消费,所以返回404
|
//该事件无人消费,所以返回404
|
||||||
invoker("404 Not Found",KeyValue(),"");
|
invoker("404 Not Found",KeyValue(),"");
|
||||||
|
if(bClose){
|
||||||
|
//close类型,回复完毕,关闭连接
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
@ -622,30 +626,28 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) {
|
|||||||
GET_CONFIG_AND_REGISTER(int,maxReqCnt,Config::Http::kMaxReqCount);
|
GET_CONFIG_AND_REGISTER(int,maxReqCnt,Config::Http::kMaxReqCount);
|
||||||
|
|
||||||
int64_t totalContentLen = m_parser["Content-Length"].empty() ? -1 : atoll(m_parser["Content-Length"].data());
|
int64_t totalContentLen = m_parser["Content-Length"].empty() ? -1 : atoll(m_parser["Content-Length"].data());
|
||||||
bool bClose = (strcasecmp(m_parser["Connection"].data(),"close") == 0) || ( ++m_iReqCnt > maxReqCnt);
|
|
||||||
|
|
||||||
if(totalContentLen == 0){
|
if(totalContentLen == 0){
|
||||||
|
//content为空
|
||||||
|
//emitHttpEvent内部会选择是否关闭连接
|
||||||
emitHttpEvent(true);
|
emitHttpEvent(true);
|
||||||
return !bClose;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(totalContentLen > 0 && totalContentLen < maxReqSize ){
|
if(totalContentLen > 0 && totalContentLen < maxReqSize ){
|
||||||
//返回固定长度的content
|
//返回固定长度的content
|
||||||
content_len = totalContentLen;
|
content_len = totalContentLen;
|
||||||
auto parserCopy = m_parser;
|
auto parserCopy = m_parser;
|
||||||
m_contentCallBack = [this,parserCopy,bClose](const string &content){
|
m_contentCallBack = [this,parserCopy](const string &content){
|
||||||
//恢复http头
|
//恢复http头
|
||||||
m_parser = parserCopy;
|
m_parser = parserCopy;
|
||||||
//设置content
|
//设置content
|
||||||
m_parser.setContent(content);
|
m_parser.setContent(content);
|
||||||
//触发http事件
|
//触发http事件,emitHttpEvent内部会选择是否关闭连接
|
||||||
emitHttpEvent(true);
|
emitHttpEvent(true);
|
||||||
//清空数据,节省内存
|
//清空数据,节省内存
|
||||||
m_parser.Clear();
|
m_parser.Clear();
|
||||||
//m_contentCallBack是不可持续的,收到一次content后就销毁
|
//content已经接收完毕
|
||||||
if(bClose){
|
|
||||||
shutdown();
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
@ -653,6 +655,8 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) {
|
|||||||
content_len = -1;
|
content_len = -1;
|
||||||
auto parserCopy = m_parser;
|
auto parserCopy = m_parser;
|
||||||
std::shared_ptr<int64_t> recvedContentLen = std::make_shared<int64_t>(0);
|
std::shared_ptr<int64_t> recvedContentLen = std::make_shared<int64_t>(0);
|
||||||
|
bool bClose = (strcasecmp(m_parser["Connection"].data(),"close") == 0) || ( ++m_iReqCnt > maxReqCnt);
|
||||||
|
|
||||||
m_contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const string &content){
|
m_contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const string &content){
|
||||||
*(recvedContentLen) += content.size();
|
*(recvedContentLen) += content.size();
|
||||||
|
|
||||||
@ -669,14 +673,17 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) {
|
|||||||
//keep-alive类型连接
|
//keep-alive类型连接
|
||||||
//content接收完毕,后续都是http header
|
//content接收完毕,后续都是http header
|
||||||
setContentLen(0);
|
setContentLen(0);
|
||||||
|
//content已经接收完毕
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//连接类型是close类型,收完content就关闭连接
|
//连接类型是close类型,收完content就关闭连接
|
||||||
shutdown();
|
shutdown();
|
||||||
|
//content已经接收完毕
|
||||||
return false ;
|
return false ;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
//有后续content数据要处理,暂时不关闭连接
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void HttpSession::responseDelay(const string &Origin,bool bClose,
|
void HttpSession::responseDelay(const string &Origin,bool bClose,
|
||||||
|
Loading…
Reference in New Issue
Block a user