Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the request shared_ptr from the multipart parser #1984

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
Remove the request shared_ptr from the multipart parser
  • Loading branch information
an-tao committed Mar 27, 2024
commit e0320ef4e70cb8880cdab7b8f380e06885a29270
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
Loading