Add http pipelining request support (#3154)

Support recv multi http request before reponse it.

Co-authored-by: 夏楚 <771730766@qq.com>
This commit is contained in:
xiongguangjie 2023-12-23 21:27:28 +08:00 committed by GitHub
parent 8f4e76406c
commit 9d68b668fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -124,29 +124,18 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
} }
//// body size明确指定且小于最大值的情况 //// //// body size明确指定且小于最大值的情况 ////
auto body = std::make_shared<std::string>(); _on_recv_body = [this, it](const char *data, size_t len) mutable {
// 预留一定的内存buffer防止频繁的内存拷贝
body->reserve(content_len);
_on_recv_body = [this, body, content_len, it](const char *data, size_t len) mutable {
body->append(data, len);
if (body->size() < content_len) {
// 未收满数据
return true;
}
// 收集body完毕 // 收集body完毕
_parser.setContent(std::move(*body)); _parser.setContent(std::string(data, len));
(this->*(it->second))(); (this->*(it->second))();
_parser.clear(); _parser.clear();
// 后续是header // _on_recv_body置空
setContentLen(0);
return false; return false;
}; };
// 声明后续都是bodyHttp body在本对象缓冲不通过HttpRequestSplitter保存 // 声明body长度通过HttpRequestSplitter缓存然后一次性回调到_on_recv_body
return -1; return content_len;
} }
void HttpSession::onRecvContent(const char *data, size_t len) { void HttpSession::onRecvContent(const char *data, size_t len) {