Move Boundary retrival into Utilities
This commit is contained in:
16
src/main.cpp
16
src/main.cpp
@ -1019,7 +1019,6 @@ int main(int argc, char *argv[]) {
|
||||
ID_SELECT_FREELANCER_NAME
|
||||
});
|
||||
|
||||
|
||||
string freelancerName, freelancerID;
|
||||
pqxx::result freelancerNameResult = Database::executePreparedStatement_SELECT_FREELANCER_NAME(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
||||
freelancerName = freelancerNameResult.at(0).at(0).c_str();
|
||||
@ -1027,25 +1026,14 @@ int main(int argc, char *argv[]) {
|
||||
freelancerID = freelancerIDResult.at(0).at(0).c_str();
|
||||
|
||||
string formDataBoundary;
|
||||
|
||||
//get boundary
|
||||
for (const auto &header: postRequest.headers) {
|
||||
if (header.first == "Content-Type") {
|
||||
string boundaryHeaderName = "boundary=";
|
||||
std::size_t contentTypeStart = header.second.find(boundaryHeaderName);
|
||||
if (contentTypeStart == string::npos) {
|
||||
if (!Utilities::getBoundaryFromPostRequest(formDataBoundary, postRequest))
|
||||
return crow::response(400, "Boundary could not be found");
|
||||
break;
|
||||
}
|
||||
contentTypeStart += boundaryHeaderName.size() + 1;
|
||||
formDataBoundary = header.second.substr(contentTypeStart, header.second.size());
|
||||
}
|
||||
}
|
||||
|
||||
//check if boundary is in body
|
||||
size_t positionBoundaryStart = postRequest.body.find(formDataBoundary);
|
||||
if (positionBoundaryStart == string::npos)
|
||||
return crow::response(400, "Content Boundary could not be found in the body of the request");
|
||||
|
||||
size_t positionBoundaryEnd = postRequest.body.find(formDataBoundary + "--");
|
||||
if (positionBoundaryEnd == string::npos)
|
||||
return crow::response(400, "Content Boundary could not be found in the body of the request");
|
||||
|
@ -826,5 +826,25 @@ namespace Utilities {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses headers of a request to find the boundary.
|
||||
* boundary is written onto formDataBoundary
|
||||
* returns false if no boundary was found
|
||||
*/
|
||||
bool getBoundaryFromPostRequest(std::string& formDataBoundary, const crow::request& postRequest) {
|
||||
for (const auto &header: postRequest.headers) {
|
||||
if (header.first == "Content-Type") {
|
||||
std::string boundaryHeaderName = "boundary=";
|
||||
std::size_t contentTypeStart = header.second.find(boundaryHeaderName);
|
||||
if (contentTypeStart == std::string::npos)
|
||||
return false;
|
||||
contentTypeStart += boundaryHeaderName.size() + 1;
|
||||
formDataBoundary = header.second.substr(contentTypeStart, header.second.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user