improve the parsing of form data
This commit is contained in:
@@ -130,6 +130,7 @@ protected:
|
||||
|
||||
bool ParseHeaderLine(const std::string& line);
|
||||
|
||||
// Parse the given length of data.
|
||||
virtual bool ParseContent(const char* data, std::size_t length);
|
||||
|
||||
bool ParseFixedContent(const char* data, std::size_t length);
|
||||
|
||||
+12
-11
@@ -50,14 +50,10 @@ bool RequestParser::ParseStartLine(const std::string& line) {
|
||||
}
|
||||
|
||||
bool RequestParser::ParseContent(const char* data, std::size_t length) {
|
||||
if (chunked_) {
|
||||
return ParseChunkedContent(data, length);
|
||||
if (content_type_.multipart()) {
|
||||
return ParseMultipartContent(data, length);
|
||||
} else {
|
||||
if (content_type_.multipart()) {
|
||||
return ParseMultipartContent(data, length);
|
||||
} else {
|
||||
return ParseFixedContent(data, length);
|
||||
}
|
||||
return Parser::ParseContent(data, length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,13 +111,18 @@ bool RequestParser::ParseMultipartContent(const char* data,
|
||||
std::size_t off = 0;
|
||||
std::size_t count = 0;
|
||||
bool ended = false;
|
||||
|
||||
// TODO: Remember last CRLF position.
|
||||
if (!GetNextBoundaryLine(&off, &count, &ended)) {
|
||||
// Wait until next boundary.
|
||||
|
||||
bool next_boundary_found = GetNextBoundaryLine(&off, &count, &ended);
|
||||
|
||||
if (!next_boundary_found) {
|
||||
part_->AppendData(pending_data_);
|
||||
pending_data_.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_INFO("Next boundary found.");
|
||||
// Next boundary found.
|
||||
|
||||
// This part has ended.
|
||||
if (off > 2) {
|
||||
@@ -269,7 +270,7 @@ bool RequestParser::IsBoundary(const std::string& str, std::size_t off,
|
||||
*end = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return strncmp(boundary.c_str(), &str[off + 2], boundary.size()) == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ private:
|
||||
// asks for data streaming.
|
||||
bool OnHeadersEnd() override;
|
||||
|
||||
bool Stream() const;
|
||||
|
||||
bool ParseStartLine(const std::string& line) override;
|
||||
|
||||
// Override to handle multipart form data which is request only.
|
||||
@@ -51,13 +49,14 @@ private:
|
||||
// received. The parsing will stop and fail if no view can be matched.
|
||||
ViewMatcher view_matcher_;
|
||||
|
||||
// Form data parsing step.
|
||||
// Form data parsing steps.
|
||||
enum Step {
|
||||
kStart,
|
||||
kBoundaryParsed,
|
||||
kHeadersParsed,
|
||||
kEnded,
|
||||
};
|
||||
|
||||
Step step_ = kStart;
|
||||
|
||||
// The current form part being parsed.
|
||||
|
||||
Reference in New Issue
Block a user