Require explicit transfer-encoding: chunked for said parsing to begin

This commit is contained in:
Alex Hultman
2022-10-17 21:34:55 +02:00
parent bcf5034e3c
commit 6cb37f9b00
+17 -12
View File
@@ -305,19 +305,24 @@ private:
consumedTotal += emittable; consumedTotal += emittable;
} }
} else { } else {
/* We are not GET and we have no content-length, so assume transfer-encoding: chunked */ /* We are not GET and we have no content-length */
remainingStreamingBytes = STATE_IS_CHUNKED; if (req->getHeader("transfer-encoding").find("chunked") != std::string_view::npos) {
/* If consume minimally, we do not want to consume anything but we want to mark this as being chunked */ remainingStreamingBytes = STATE_IS_CHUNKED;
if (!CONSUME_MINIMALLY) { /* If consume minimally, we do not want to consume anything but we want to mark this as being chunked */
/* Go ahead and parse it (todo: better heuristics for emitting FIN to the app level) */ if (!CONSUME_MINIMALLY) {
std::string_view dataToConsume(data, length); /* Go ahead and parse it (todo: better heuristics for emitting FIN to the app level) */
for (auto chunk : uWS::ChunkIterator(&dataToConsume, &remainingStreamingBytes)) { std::string_view dataToConsume(data, length);
dataHandler(user, chunk, chunk.length() == 0); for (auto chunk : uWS::ChunkIterator(&dataToConsume, &remainingStreamingBytes)) {
dataHandler(user, chunk, chunk.length() == 0);
}
unsigned int consumed = (length - (unsigned int) dataToConsume.length());
data = (char *) dataToConsume.data();
length = (unsigned int) dataToConsume.length();
consumedTotal += consumed;
} }
unsigned int consumed = (length - (unsigned int) dataToConsume.length()); } else {
data = (char *) dataToConsume.data(); /* We have no content-length and no transfer-encoding: chunked */
length = (unsigned int) dataToConsume.length(); dataHandler(user, {}, true);
consumedTotal += consumed;
} }
} }
} else { } else {