Merge pull request #153 from an-tao/dev

Modify the HttpRequestParser class to improve performance
This commit is contained in:
An Tao 2019-05-16 17:56:07 +08:00 committed by GitHub
commit 3647f8c80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,6 +214,7 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
shutdownConnection(k413RequestEntityTooLarge);
return false;
}
_request->_content.reserve(_request->_contentLen);
}
else
{
@ -251,12 +252,12 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
if (_request->_contentLen >= buf->readableBytes())
{
_request->_contentLen -= buf->readableBytes();
_request->_content += std::string(buf->peek(), buf->readableBytes());
_request->_content.append(buf->peek(), buf->readableBytes());
buf->retrieveAll();
}
else
{
_request->_content += std::string(buf->peek(), _request->_contentLen);
_request->_content.append(buf->peek(), _request->_contentLen);
buf->retrieve(_request->_contentLen);
_request->_contentLen = 0;
}