Can't use starts_with, also has to strip rn before/after
This commit is contained in:
+9
-10
@@ -44,7 +44,7 @@ namespace uWS {
|
|||||||
MultipartParser(std::string_view contentType) {
|
MultipartParser(std::string_view contentType) {
|
||||||
|
|
||||||
/* We expect the form "multipart/something;somethingboundary=something" */
|
/* We expect the form "multipart/something;somethingboundary=something" */
|
||||||
if (!contentType.starts_with("multipart/")) {
|
if (contentType.length() < 10 || contentType.substr(0, 10) != "multipart/") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +108,14 @@ namespace uWS {
|
|||||||
std::string_view part = remainingBody.substr(0, nextEndBoundary);
|
std::string_view part = remainingBody.substr(0, nextEndBoundary);
|
||||||
remainingBody.remove_prefix(nextEndBoundary + prependedBoundary.length());
|
remainingBody.remove_prefix(nextEndBoundary + prependedBoundary.length());
|
||||||
|
|
||||||
|
/* Also strip rn before and rn after the part */
|
||||||
|
if (part.length() < 4) {
|
||||||
|
/* Cannot strip */
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
part.remove_prefix(2);
|
||||||
|
part.remove_suffix(2);
|
||||||
|
|
||||||
/* We are allowed to post pad like this because we know the boundary is at least 2 bytes */
|
/* We are allowed to post pad like this because we know the boundary is at least 2 bytes */
|
||||||
/* This makes parsing a second pass invalid, so you can only iterate over parts once */
|
/* This makes parsing a second pass invalid, so you can only iterate over parts once */
|
||||||
memset((char *) part.data() + part.length(), '\r', 1);
|
memset((char *) part.data() + part.length(), '\r', 1);
|
||||||
@@ -120,15 +128,6 @@ namespace uWS {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is to be done by the user, not the parser */
|
|
||||||
/*for (int i = 0; i < MAX_HEADERS; i++) {
|
|
||||||
if (headers[i].first.length()) {
|
|
||||||
std::cout << "<" << headers[i].first << "> = <" << headers[i].second << ">" << std::endl;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* Strip away the headers from the part body data */
|
/* Strip away the headers from the part body data */
|
||||||
part.remove_prefix(consumed);
|
part.remove_prefix(consumed);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user