Skip to content

Commit

Permalink
fix bug of parser http header values.
Browse files Browse the repository at this point in the history
  • Loading branch information
IronsDu committed Sep 18, 2020
1 parent f9d2804 commit 0a3f887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
26 changes: 11 additions & 15 deletions include/brynet/net/http/HttpParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,17 @@ namespace brynet { namespace net { namespace http {
private:
void clearParse()
{
mMethod = -1;
mISCompleted = false;
mLastWasValue = true;
mUrl.clear();
mQuery.clear();
mBody.clear();
mStatus.clear();
mCurrentField.clear();
mCurrentValue.clear();
mHeadValues.clear();
mPath.clear();
mQuery.clear();
}

size_t tryParse(const char* buffer, size_t len)
Expand Down Expand Up @@ -179,9 +186,7 @@ namespace brynet { namespace net { namespace http {
static int sMessageBegin(http_parser* hp)
{
HTTPParser* httpParser = (HTTPParser*)hp->data;
httpParser->mLastWasValue = true;
httpParser->mCurrentField.clear();
httpParser->mCurrentValue.clear();
httpParser->clearParse();

return 0;
}
Expand All @@ -196,10 +201,6 @@ namespace brynet { namespace net { namespace http {
static int sHeadComplete(http_parser* hp)
{
HTTPParser* httpParser = (HTTPParser*)hp->data;
if (!httpParser->mCurrentField.empty())
{
httpParser->mHeadValues[httpParser->mCurrentField] = httpParser->mCurrentValue;
}

if (httpParser->mUrl.empty())
{
Expand Down Expand Up @@ -249,7 +250,8 @@ namespace brynet { namespace net { namespace http {
static int sHeadValue(http_parser* hp, const char* at, size_t length)
{
HTTPParser* httpParser = (HTTPParser*)hp->data;
httpParser->mCurrentValue.append(at, length);
auto& value = httpParser->mHeadValues[httpParser->mCurrentField];
value.append(at, length);
httpParser->mLastWasValue = true;
return 0;
}
Expand All @@ -259,14 +261,8 @@ namespace brynet { namespace net { namespace http {
HTTPParser* httpParser = (HTTPParser*)hp->data;
if (httpParser->mLastWasValue)
{
if (!httpParser->mCurrentField.empty())
{
sHeadComplete(hp);
}
httpParser->mCurrentField.clear();
httpParser->mCurrentValue.clear();
}

httpParser->mCurrentField.append(at, length);
httpParser->mLastWasValue = false;

Expand Down
4 changes: 0 additions & 4 deletions include/brynet/net/http/HttpService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ namespace brynet { namespace net { namespace http {
{
httpCallback(*httpParser, httpSession);
}
if (httpParser->isKeepAlive())
{
httpParser->clearParse();
}
}

return retlen;
Expand Down

0 comments on commit 0a3f887

Please sign in to comment.