From 0bf75529a2932e7aaa10912a3427e453601781b3 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 24 Dec 2021 13:10:52 +0800 Subject: [PATCH] =?UTF-8?q?HTTP:=20=E7=A1=AE=E4=BF=9Dhttp=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=BB=93=E6=9D=9F=E5=90=8E=E4=B8=8D=E5=86=8D=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E8=B6=85=E6=97=B6=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- src/Http/HttpClient.cpp | 8 +++++++- src/Http/HttpClient.h | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index be36a863..88bc73aa 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit be36a8637a53c707e8cc293b66e153edde55afa1 +Subproject commit 88bc73aa6b7e04e04ca45f4fdbe36d4e359088bf diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index f9117e8b..e4829429 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -100,6 +100,7 @@ void HttpClient::clear() { } void HttpClient::clearResponse() { + _complete = false; _recved_body_size = 0; _total_body_size = 0; _parser.Clear(); @@ -283,16 +284,21 @@ void HttpClient::onManager() { onResponseCompleted_l(); } - if (_timeout_second > 0 && _total_timeout_ticker.elapsedTime() > _timeout_second * 1000) { + if (waitResponse() && _timeout_second > 0 && _total_timeout_ticker.elapsedTime() > _timeout_second * 1000) { //超时 shutdown(SockException(Err_timeout, "http request timeout")); } } void HttpClient::onResponseCompleted_l() { + _complete = true; onResponseCompleted(); } +bool HttpClient::waitResponse() const { + return !_complete && alive(); +} + void HttpClient::checkCookie(HttpClient::HttpHeader &headers) { //Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/ for (auto it_set_cookie = headers.find("Set-Cookie"); it_set_cookie != headers.end(); ++it_set_cookie) { diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 4e32dbf1..69d7ff46 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -106,6 +106,11 @@ public: */ const string &getUrl() const; + /** + * 判断是否正在等待响应 + */ + bool waitResponse() const; + protected: /** * 收到http回复头 @@ -173,6 +178,7 @@ protected: bool _is_https; private: + bool _complete = false; string _url; HttpHeader _header; HttpBody::Ptr _body;