Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions muduo/net/http/HttpContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,16 @@ bool HttpContext::parseRequest(Buffer* buf, Timestamp receiveTime)
else
{
// empty line, end of header
// FIXME:
state_ = kGotAll;
hasMore = false;
// FIXME: can other http method contain a body?
if (request_.method() == kGet)
{
state_ = kGotAll;
hasMore = false;
}
else if (request_.method() == kPost)
{
state_ = kExpectBody;
}
}
buf->retrieveUntil(crlf + 2);
}
Expand All @@ -111,7 +118,13 @@ bool HttpContext::parseRequest(Buffer* buf, Timestamp receiveTime)
}
else if (state_ == kExpectBody)
{
// FIXME:
// FIXME: can other http method contain a body?
if (request_.method() == kPost)
{
request_.setBody(buf->retrieveAllAsString());
state_ = kGotAll;
hasMore = false;
}
}
}
return ok;
Expand Down
7 changes: 7 additions & 0 deletions muduo/net/http/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class HttpRequest : public muduo::copyable
const std::map<string, string>& headers() const
{ return headers_; }

void setBody(string content)
{ body_ = content; }

const string& getBody() const
{ return body_; }

void swap(HttpRequest& that)
{
std::swap(method_, that.method_);
Expand All @@ -177,6 +183,7 @@ class HttpRequest : public muduo::copyable
Version version_;
string path_;
string query_;
string body_;
Timestamp receiveTime_;
std::map<string, string> headers_;
};
Expand Down