Skip to content

Commit

Permalink
Remove the request shared_ptr from the multipart parser (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
an-tao authored Mar 27, 2024
1 parent 4cbac30 commit 9f28726
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/inc/drogon/MultiPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ class DROGON_EXPORT MultiPartParser
int parse(const HttpRequestPtr &req,
const char *boundaryData,
size_t boundaryLen);
int parseEntity(const char *begin, const char *end);
HttpRequestPtr requestPtr_;
int parseEntity(const HttpRequestPtr &req,
const char *begin,
const char *end);
};

/// In order to be compatible with old interfaces
Expand Down
9 changes: 5 additions & 4 deletions lib/src/MultiPart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ static std::pair<std::string_view, std::string_view> parseLine(
return std::make_pair(std::string_view(), std::string_view());
}

int MultiPartParser::parseEntity(const char *begin, const char *end)
int MultiPartParser::parseEntity(const HttpRequestPtr &req,
const char *begin,
const char *end)
{
static const char entityName[] = "name=";
static const char fileName[] = "filename=";
Expand Down Expand Up @@ -174,7 +176,7 @@ int MultiPartParser::parseEntity(const char *begin, const char *end)
fileNameEnd = std::find(fileNamePos, valueEnd, ';');
}
std::string fName{fileNamePos, fileNameEnd};
filePtr->setRequest(requestPtr_);
filePtr->setRequest(req);
filePtr->setItemName(std::move(name));
filePtr->setFileName(std::move(fName));
filePtr->setFile(headEnd + 2,
Expand Down Expand Up @@ -218,7 +220,6 @@ int MultiPartParser::parse(const HttpRequestPtr &req,
std::string_view boundary{boundaryData, boundaryLen};
if (boundary.size() > 2 && boundary[0] == '\"')
boundary = boundary.substr(1, boundary.size() - 2);
requestPtr_ = req;
std::string_view::size_type pos1, pos2;
pos1 = 0;
auto content = static_cast<HttpRequestImpl *>(req.get())->bodyView();
Expand All @@ -241,7 +242,7 @@ int MultiPartParser::parse(const HttpRequestPtr &req,
pos2 -= 4;
flag = true;
}
if (parseEntity(content.data() + pos1, content.data() + pos2) != 0)
if (parseEntity(req, content.data() + pos1, content.data() + pos2) != 0)
return -1;
if (flag)
pos2 += 4;
Expand Down

0 comments on commit 9f28726

Please sign in to comment.