diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index 71081a3f..3181efe6 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -186,7 +186,7 @@ int64_t HttpClient::onRecvHeader(const char *data, uint64_t len) { //所以返回-1代表我们接下来分段接收content _recvedBodySize = 0; //根据_totalBodySize设置接收缓存大小 - _sock->setReadBuffer(std::make_shared(MAX(_totalBodySize + 1,256 * 1024))); + _sock->setReadBuffer(std::make_shared(MIN(_totalBodySize + 1,256 * 1024))); return -1; } diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 7200fce7..2b6a1b78 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -635,7 +635,15 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) { return true; } - if(totalContentLen > 0 && totalContentLen < maxReqSize ){ + //根据Content-Length设置接收缓存大小 + if(totalContentLen > 0){ + _sock->setReadBuffer(std::make_shared(MIN(totalContentLen + 1,256 * 1024))); + }else{ + //不定长度的Content-Length + _sock->setReadBuffer(std::make_shared(256 * 1024)); + } + + if(totalContentLen > 0 && totalContentLen < maxReqSize ){ //返回固定长度的content content_len = totalContentLen; auto parserCopy = _parser; @@ -652,9 +660,6 @@ inline bool HttpSession::Handle_Req_POST(int64_t &content_len) { return false; }; }else{ - //如果是post请求 并且totalContentLen数据超过maxReqSize,那么我们加大接收缓存提升性能 - _sock->setReadBuffer(std::make_shared(256 * 1024)); - //返回不固定长度的content content_len = -1; auto parserCopy = _parser;