From e99effc1d015dfe7aa4a636a67dd56dd8243e5ae Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 23 Sep 2018 21:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontent-length=E4=B8=BA0?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=A7=A6=E5=8F=91onResponseCompleted?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpClient.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index e6bc4c20..010ae111 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -139,15 +139,28 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) { _parser.Parse(data); onResponseHeader(_parser.Url(), _parser.getValues()); - if (_parser["Content-Length"].empty() && !_parser.Content().empty()) { - //如果http回复未声明Content-Length字段,但是却有content内容,那说明可能是个不限长度的content - _totalBodySize = INT64_MAX; - _recvedBodySize = 0; - //返回-1代表不限制content回复大小 - return -1; + if(_parser["Content-Length"].empty()){ + //没有Content-Length字段 + if(!_parser.Content().empty()){ + //如果http回复未声明Content-Length字段,但是却有content内容,那说明可能是个不限长度的content + _totalBodySize = INT64_MAX; + _recvedBodySize = 0; + //返回-1代表不限制content回复大小 + return -1; + } + //content长度为0,本次http请求结束 + onResponseCompleted_l(); + return 0; } - _totalBodySize = atoll(_parser["Content-Length"].data()); + _recvedBodySize = 0; + _totalBodySize = atoll(_parser["Content-Length"].data()); + + if(_totalBodySize == 0){ + //content长度为0,本次http请求结束 + onResponseCompleted_l(); + return 0; + } //虽然我们知道content的确切大小, //但是由于我们没必要等content接收完毕才回调onRecvContent(因为这样浪费内存并且要多次拷贝数据)