Skip to content

Commit 9dcf1ae

Browse files
committed
keep same behavior
1 parent f6c6763 commit 9dcf1ae

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/bun-uws/src/HttpParser.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ namespace uWS
487487
if (nextPosition >= end) {
488488
/* Whatever we have must be part of the version string */
489489
if (memcmp(" HTTP/1.1\r\n", data, std::min<unsigned int>(11, (unsigned int) (end - data))) == 0) {
490-
return ConsumeRequestLineResult::shortRead(false);
490+
return ConsumeRequestLineResult::shortRead();
491491
} else if (memcmp(" HTTP/1.0\r\n", data, std::min<unsigned int>(11, (unsigned int) (end - data))) == 0) {
492492
return ConsumeRequestLineResult::shortRead(true);
493493
}
@@ -500,7 +500,7 @@ namespace uWS
500500
}
501501
/* If we stand at the post padded CR, we have fragmented input so try again later */
502502
if (data[0] == '\r') {
503-
return ConsumeRequestLineResult::shortRead(false);
503+
return ConsumeRequestLineResult::shortRead();
504504
}
505505
/* This is an error */
506506
return ConsumeRequestLineResult::error(HTTP_HEADER_PARSER_ERROR_INVALID_HTTP_VERSION);
@@ -510,14 +510,14 @@ namespace uWS
510510

511511
/* If we stand at the post padded CR, we have fragmented input so try again later */
512512
if (data[0] == '\r') {
513-
return ConsumeRequestLineResult::shortRead(false);
513+
return ConsumeRequestLineResult::shortRead();
514514
}
515515

516516
if (data[0] == 32) {
517517
switch (isHTTPorHTTPSPrefixForProxies(data + 1, end)) {
518518
// If we haven't received enough data to check if it's http:// or https://, let's try again later
519519
case -1:
520-
return ConsumeRequestLineResult::shortRead(false);
520+
return ConsumeRequestLineResult::shortRead();
521521
// Otherwise, if it's not http:// or https://, return 400
522522
default:
523523
return ConsumeRequestLineResult::error(HTTP_HEADER_PARSER_ERROR_INVALID_REQUEST);
@@ -891,9 +891,11 @@ namespace uWS
891891

892892
// break here on break
893893
HttpParserResult consumed = fenceAndConsumePostPadded<true>(requireHostHeader,fallback.data(), (unsigned int) fallback.length(), user, reserved, &req, requestHandler, dataHandler);
894-
if (consumed.httpErrorStatusCode()) {
894+
/* Return data will be different than user if we are upgraded to WebSocket or have an error */
895+
if (consumed.returnedData != user) {
895896
return consumed;
896897
}
898+
/* safe to call consumed.consumedBytes() because consumed.returnedData == user */
897899
auto consumedBytes = consumed.consumedBytes();
898900
if (consumedBytes) {
899901

@@ -946,9 +948,11 @@ namespace uWS
946948
}
947949

948950
HttpParserResult consumed = fenceAndConsumePostPadded<false>(requireHostHeader,data, length, user, reserved, &req, requestHandler, dataHandler);
949-
if (consumed.httpErrorStatusCode()) {
951+
/* Return data will be different than user if we are upgraded to WebSocket or have an error */
952+
if (consumed.returnedData != user) {
950953
return consumed;
951954
}
955+
/* safe to call consumed.consumedBytes() because consumed.returnedData == user */
952956
auto consumedBytes = consumed.consumedBytes();
953957

954958
data += consumedBytes;

0 commit comments

Comments
 (0)