mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-01 23:57:37 +08:00
完善错误提示
This commit is contained in:
@@ -130,7 +130,7 @@ void HttpClient::onConnect(const SockException &ex) {
|
||||
printer << pr.second + "\r\n";
|
||||
}
|
||||
send(printer << "\r\n");
|
||||
onSend();
|
||||
onFlush();
|
||||
}
|
||||
|
||||
void HttpClient::onRecv(const Buffer::Ptr &pBuf) {
|
||||
@@ -222,12 +222,11 @@ void HttpClient::onRecvContent(const char *data, uint64_t len) {
|
||||
onResponseCompleted_l();
|
||||
if(biggerThanExpected) {
|
||||
//声明的content数据比真实的小,那么我们只截取前面部分的并断开链接
|
||||
shutdown();
|
||||
onDisconnect(SockException(Err_other, "http response content size bigger than expected"));
|
||||
shutdown(SockException(Err_shutdown, "http response content size bigger than expected"));
|
||||
}
|
||||
}
|
||||
|
||||
void HttpClient::onSend() {
|
||||
void HttpClient::onFlush() {
|
||||
_aliveTicker.resetTime();
|
||||
while (_body && _body->remainSize() && !isSocketBusy()) {
|
||||
auto buffer = _body->readData();
|
||||
@@ -252,8 +251,7 @@ void HttpClient::onManager() {
|
||||
|
||||
if (_fTimeOutSec > 0 && _aliveTicker.elapsedTime() > _fTimeOutSec * 1000) {
|
||||
//超时
|
||||
onDisconnect(SockException(Err_timeout, "http request timeout"));
|
||||
shutdown();
|
||||
shutdown(SockException(Err_timeout, "http request timeout"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ protected:
|
||||
virtual void onConnect(const SockException &ex) override;
|
||||
virtual void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
virtual void onErr(const SockException &ex) override;
|
||||
virtual void onSend() override;
|
||||
virtual void onFlush() override;
|
||||
virtual void onManager() override;
|
||||
private:
|
||||
void onResponseCompleted_l();
|
||||
|
||||
@@ -66,14 +66,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo
|
||||
int64_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) {
|
||||
if(status != "200" && status != "206"){
|
||||
//失败
|
||||
shutdown();
|
||||
closeFile();
|
||||
File::delete_file(_filePath.data());
|
||||
if(_onResult){
|
||||
auto errMsg = StrPrinter << "Http Status:" << status << endl;
|
||||
_onResult(Err_other,errMsg,_filePath);
|
||||
_onResult = nullptr;
|
||||
}
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "Http Status:" << status));
|
||||
}
|
||||
//后续全部是content
|
||||
return -1;
|
||||
|
||||
@@ -101,6 +101,7 @@ get_mime_type(const char* name) {
|
||||
|
||||
|
||||
HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
TraceP(this);
|
||||
//设置15秒发送超时时间
|
||||
pSock->setSendTimeOutSecond(15);
|
||||
//起始接收buffer缓存设置为4K,节省内存
|
||||
@@ -108,7 +109,7 @@ HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
}
|
||||
|
||||
HttpSession::~HttpSession() {
|
||||
//DebugL;
|
||||
TraceP(this);
|
||||
}
|
||||
|
||||
int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||
@@ -124,17 +125,16 @@ int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||
string cmd = _parser.Method();
|
||||
auto it = g_mapCmdIndex.find(cmd);
|
||||
if (it == g_mapCmdIndex.end()) {
|
||||
WarnP(this) << cmd;
|
||||
sendResponse("403 Forbidden", makeHttpHeader(true), "");
|
||||
shutdown();
|
||||
return 0;
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "403 Forbidden:" << cmd));
|
||||
return 0;
|
||||
}
|
||||
|
||||
//默认后面数据不是content而是header
|
||||
int64_t content_len = 0;
|
||||
auto &fun = it->second;
|
||||
if(!(this->*fun)(content_len)){
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"Connection: close"));
|
||||
}
|
||||
//清空解析器节省内存
|
||||
_parser.Clear();
|
||||
@@ -156,9 +156,13 @@ void HttpSession::onRecv(const Buffer::Ptr &pBuf) {
|
||||
}
|
||||
|
||||
void HttpSession::onError(const SockException& err) {
|
||||
// WarnP(this) << err.what();
|
||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||
if(_ticker.createdTime() < 10 * 1000){
|
||||
TraceP(this) << err.what();
|
||||
}else{
|
||||
WarnP(this) << err.what();
|
||||
}
|
||||
|
||||
GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold);
|
||||
if(_ui64TotalBytes > iFlowThreshold * 1024){
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport,
|
||||
_mediaInfo,
|
||||
@@ -174,8 +178,7 @@ void HttpSession::onManager() {
|
||||
|
||||
if(_ticker.elapsedTime() > keepAliveSec * 1000){
|
||||
//1分钟超时
|
||||
// WarnP(this) <<"HttpSession timeouted!";
|
||||
shutdown();
|
||||
shutdown(SockException(Err_timeout,"session timeouted"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +236,7 @@ inline bool HttpSession::checkLiveFlvStream(){
|
||||
//未找到该流
|
||||
sendNotFound(bClose);
|
||||
if(bClose){
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"flv stream not found"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -242,7 +245,7 @@ inline bool HttpSession::checkLiveFlvStream(){
|
||||
bool authSuccess = err.empty();
|
||||
if(!authSuccess){
|
||||
sendResponse("401 Unauthorized", makeHttpHeader(true,err.size()),err);
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,StrPrinter << "401 Unauthorized:" << err));
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -258,7 +261,7 @@ inline bool HttpSession::checkLiveFlvStream(){
|
||||
start(getPoller(),rtmp_src);
|
||||
}catch (std::exception &ex){
|
||||
//该rtmp源不存在
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"rtmp mediasource released"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -446,7 +449,7 @@ inline bool HttpSession::Handle_Req_GET(int64_t &content_len) {
|
||||
strongSelf->send(sendBuf);
|
||||
}
|
||||
if(bClose) {
|
||||
strongSelf->shutdown();
|
||||
strongSelf->shutdown(SockException(Err_shutdown,"read file eof"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -645,7 +648,7 @@ inline bool HttpSession::emitHttpEvent(bool doInvoke){
|
||||
}
|
||||
strongSelf->responseDelay(Origin,bClose,codeOut,headerOut,contentOut);
|
||||
if(bClose){
|
||||
strongSelf->shutdown();
|
||||
strongSelf->shutdown(SockException(Err_shutdown,"Connection: close"));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -657,7 +660,7 @@ inline bool HttpSession::emitHttpEvent(bool doInvoke){
|
||||
invoker("404 Not Found",KeyValue(),"");
|
||||
if(bClose){
|
||||
//close类型,回复完毕,关闭连接
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"404 Not Found"));
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
@@ -727,7 +730,7 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) {
|
||||
}
|
||||
|
||||
//连接类型是close类型,收完content就关闭连接
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"recv http content completed"));
|
||||
//content已经接收完毕
|
||||
return false ;
|
||||
};
|
||||
@@ -763,7 +766,7 @@ void HttpSession::onWrite(const Buffer::Ptr &buffer) {
|
||||
}
|
||||
|
||||
void HttpSession::onDetach() {
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"rtmp ring buffer detached"));
|
||||
}
|
||||
|
||||
std::shared_ptr<FlvMuxer> HttpSession::getSharedPtr(){
|
||||
|
||||
@@ -83,13 +83,11 @@ protected:
|
||||
uint64_t len,
|
||||
uint64_t totalSize,
|
||||
uint64_t recvedSize){
|
||||
WarnL << "content数据长度过大,无法处理,请重载HttpSession::onRecvUnlimitedContent";
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"http post content is too huge,default closed"));
|
||||
}
|
||||
|
||||
void onWebSocketDecodeHeader(const WebSocketHeader &packet) override{
|
||||
DebugL << "默认关闭WebSocket";
|
||||
shutdown();
|
||||
shutdown(SockException(Err_shutdown,"websocket connection default closed"));
|
||||
};
|
||||
|
||||
void onRecvWebSocketData(const Parser &header,const char *data,uint64_t len){
|
||||
|
||||
Reference in New Issue
Block a user