Skip to content

Commit b254f7c

Browse files
authored
Merge pull request #20 from jimbobbennett/master
Chunking WiFi client writes in the HTTP client to handle large file sizes
2 parents a9f1a48 + a0931d2 commit b254f7c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/HTTPClient.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,12 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
578578

579579
// send Payload if needed
580580
if(payload && size > 0) {
581-
if(_client->write(&payload[0], size) != size) {
582-
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
581+
// Send in chunks of HTTP_TCP_BUFFER_SIZE bytes
582+
for (size_t pos = 0; pos < size; pos += HTTP_TCP_BUFFER_SIZE) {
583+
size_t to_write = min(HTTP_TCP_BUFFER_SIZE, size - pos);
584+
if(_client->write(&payload[pos], to_write) != to_write) {
585+
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
586+
}
583587
}
584588
}
585589

0 commit comments

Comments
 (0)