mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 20:15:58 +08:00
重写http客户端异常处理机制
This commit is contained in:
@@ -100,6 +100,16 @@ public:
|
||||
*/
|
||||
const Parser &response() const;
|
||||
|
||||
/**
|
||||
* 获取回复header声明的body大小
|
||||
*/
|
||||
ssize_t responseBodyTotalSize() const;
|
||||
|
||||
/**
|
||||
* 获取已经下载body的大小
|
||||
*/
|
||||
size_t responseBodySize() const;
|
||||
|
||||
/**
|
||||
* 获取请求url
|
||||
*/
|
||||
@@ -139,37 +149,20 @@ protected:
|
||||
* 收到http回复头
|
||||
* @param status 状态码,譬如:200 OK
|
||||
* @param headers http头
|
||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
||||
*/
|
||||
virtual ssize_t onResponseHeader(const string &status, const HttpHeader &headers) {
|
||||
//无Content-Length字段时默认后面全是content
|
||||
return -1;
|
||||
}
|
||||
virtual void onResponseHeader(const string &status, const HttpHeader &headers) = 0;
|
||||
|
||||
/**
|
||||
* 收到http conten数据
|
||||
* @param buf 数据指针
|
||||
* @param size 数据大小
|
||||
* @param recvedSize 已收数据大小(包含本次数据大小),当其等于totalSize时将触发onResponseCompleted回调
|
||||
* @param totalSize 总数据大小
|
||||
*/
|
||||
virtual void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||
DebugL << size << " " << recvedSize << " " << totalSize;
|
||||
}
|
||||
virtual void onResponseBody(const char *buf, size_t size) = 0;
|
||||
|
||||
/**
|
||||
* 接收http回复完毕,
|
||||
*/
|
||||
virtual void onResponseCompleted() {
|
||||
DebugL;
|
||||
}
|
||||
|
||||
/**
|
||||
* http链接断开回调
|
||||
* @param ex 断开原因
|
||||
*/
|
||||
virtual void onDisconnect(const SockException &ex) {}
|
||||
virtual void onResponseCompleted(const SockException &ex) = 0;
|
||||
|
||||
/**
|
||||
* 重定向事件
|
||||
@@ -179,11 +172,11 @@ protected:
|
||||
*/
|
||||
virtual bool onRedirectUrl(const string &url, bool temporary) { return true; };
|
||||
|
||||
protected:
|
||||
//// HttpRequestSplitter override ////
|
||||
ssize_t onRecvHeader(const char *data, size_t len) override;
|
||||
void onRecvContent(const char *data, size_t len) override;
|
||||
|
||||
protected:
|
||||
//// TcpClient override ////
|
||||
void onConnect(const SockException &ex) override;
|
||||
void onRecv(const Buffer::Ptr &pBuf) override;
|
||||
@@ -192,7 +185,7 @@ protected:
|
||||
void onManager() override;
|
||||
|
||||
private:
|
||||
void onResponseCompleted_l();
|
||||
void onResponseCompleted_l(const SockException &ex);
|
||||
void onConnect_l(const SockException &ex);
|
||||
void checkCookie(HttpHeader &headers);
|
||||
void clearResponse();
|
||||
|
||||
Reference in New Issue
Block a user