Skip to content

Commit 8f6e0dd

Browse files
earlephilhowerdevyte
authored andcommitted
Allow for POSTs larger than a few 100 bytes (#6800)
This is all @dirkx , whose PR unfortunately got borked when we were trying to update it to the new format. As @dirkx said: When sending POST responses of well over a K - _write() may not sent it all. Make sure we do -- but cap the individual writes - as somehow large 2-3k blobs seem to cause instability (on my 12F units). Supercedes #2528
1 parent 05d28bc commit 8f6e0dd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,20 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s
677677
}
678678

679679
// send Payload if needed
680-
if(payload && size > 0) {
681-
if(_client->write(&payload[0], size) != size) {
682-
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
680+
if (payload && size > 0) {
681+
size_t byteswritten = 0;
682+
const uint8_t *p = payload;
683+
while (byteswritten < size) {
684+
int written;
685+
int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE);
686+
written = _client->write(p, towrite);
687+
if (written < 0) {
688+
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
689+
} else if (written == 0) {
690+
return returnError(HTTPC_ERROR_CONNECTION_LOST);
691+
}
692+
byteswritten += written;
693+
size -= written;
683694
}
684695
}
685696

0 commit comments

Comments
 (0)