Remove the request shared_ptr from the multipart parser (#1984)

This commit is contained in:
An Tao 2024-03-27 16:02:37 +08:00 committed by GitHub
parent 4cbac301fb
commit 9f2872639a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View File

@ -178,8 +178,9 @@ class DROGON_EXPORT MultiPartParser
int parse(const HttpRequestPtr &req, int parse(const HttpRequestPtr &req,
const char *boundaryData, const char *boundaryData,
size_t boundaryLen); size_t boundaryLen);
int parseEntity(const char *begin, const char *end); int parseEntity(const HttpRequestPtr &req,
HttpRequestPtr requestPtr_; const char *begin,
const char *end);
}; };
/// In order to be compatible with old interfaces /// In order to be compatible with old interfaces

View File

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

@ -1 +1 @@
Subproject commit b4e9c8b86300419a1792b73cf60747c9c350686d Subproject commit c92280119a6ebaf71fe6aca0d128222edd028b22