Skip to content

Commit

Permalink
Fix loop exiting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jan 15, 2025
1 parent 40ad185 commit 1e4bcc7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/http/HTTPRequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream
if (state == ParserState::Invalid) {
OS_LOGE(TAG, "Failed to parse chunk");
result = HTTP::RequestResult::RequestFailed;
state = ParserState::Invalid; // Mark to exit both loops
break;
}
OS_LOGD(TAG, "Chunk parsed: %zu %zu", payloadPos, payloadSize);
Expand All @@ -284,18 +285,20 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream
if (bufferCursor == HTTP_BUFFER_SIZE) {
OS_LOGE(TAG, "Chunk too large");
result = HTTP::RequestResult::RequestFailed;
break;
state = ParserState::Invalid; // Mark to exit both loops
}
continue;
break; // If chunk size good, this only exits one loop
}

// Check for zero chunk size (end of transfer)
if (payloadSize == 0) {
state = ParserState::Invalid; // Mark to exit both loops
break;
}

if (!downloadCallback(totalWritten, buffer + payloadPos, payloadSize)) {
result = HTTP::RequestResult::Cancelled;
state = ParserState::Invalid; // Mark to exit both loops
break;
}

Expand All @@ -305,7 +308,9 @@ StreamReaderResult _readStreamDataChunked(HTTPClient& client, WiFiClient* stream
payloadPos = 0;
}

vTaskDelay(pdMS_TO_TICKS(5));
if (state == ParserState::NeedMoreData) {
vTaskDelay(pdMS_TO_TICKS(5));
}
}

free(buffer);
Expand Down

0 comments on commit 1e4bcc7

Please sign in to comment.