Empty part is not a viable indication of end
This commit is contained in:
+8
-7
@@ -24,6 +24,7 @@
|
|||||||
#include "MessageParser.h"
|
#include "MessageParser.h"
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <optional>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@@ -178,20 +179,20 @@ namespace uWS {
|
|||||||
remainingBody = body;
|
remainingBody = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse out the next part's data, filling the headers. Returns empty part on end or error */
|
/* Parse out the next part's data, filling the headers. Returns nullopt on end or error. */
|
||||||
std::string_view getNextPart(std::pair<std::string_view, std::string_view> *headers) {
|
std::optional<std::string_view> getNextPart(std::pair<std::string_view, std::string_view> *headers) {
|
||||||
|
|
||||||
/* The remaining two hyphens should be shorter than the boundary */
|
/* The remaining two hyphens should be shorter than the boundary */
|
||||||
if (remainingBody.length() < prependedBoundary.length()) {
|
if (remainingBody.length() < prependedBoundary.length()) {
|
||||||
/* We are done now */
|
/* We are done now */
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
auto nextBoundary = remainingBody.find(prependedBoundary);
|
auto nextBoundary = remainingBody.find(prependedBoundary);
|
||||||
if (nextBoundary == std::string_view::npos) {
|
if (nextBoundary == std::string_view::npos) {
|
||||||
/* Cannot parse */
|
/* Cannot parse */
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Toss away boundary and anything before it */
|
/* Toss away boundary and anything before it */
|
||||||
@@ -202,7 +203,7 @@ namespace uWS {
|
|||||||
auto nextEndBoundary = remainingBody.find(prependedBoundary);
|
auto nextEndBoundary = remainingBody.find(prependedBoundary);
|
||||||
if (nextEndBoundary == std::string_view::npos) {
|
if (nextEndBoundary == std::string_view::npos) {
|
||||||
/* Cannot parse (or simply done) */
|
/* Cannot parse (or simply done) */
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view part = remainingBody.substr(0, nextEndBoundary);
|
std::string_view part = remainingBody.substr(0, nextEndBoundary);
|
||||||
@@ -211,7 +212,7 @@ namespace uWS {
|
|||||||
/* Also strip rn before and rn after the part */
|
/* Also strip rn before and rn after the part */
|
||||||
if (part.length() < 4) {
|
if (part.length() < 4) {
|
||||||
/* Cannot strip */
|
/* Cannot strip */
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
part.remove_prefix(2);
|
part.remove_prefix(2);
|
||||||
part.remove_suffix(2);
|
part.remove_suffix(2);
|
||||||
@@ -225,7 +226,7 @@ namespace uWS {
|
|||||||
|
|
||||||
if (!consumed) {
|
if (!consumed) {
|
||||||
/* This is an invalid part */
|
/* This is an invalid part */
|
||||||
return {};
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strip away the headers from the part body data */
|
/* Strip away the headers from the part body data */
|
||||||
|
|||||||
Reference in New Issue
Block a user