Skip to content

Commit d7ef9ad

Browse files
Allow for POSTs larger than a few 100 bytes
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 esp8266#2528
1 parent 01e9d94 commit d7ef9ad

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
@@ -678,9 +678,20 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s
678678
}
679679

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

0 commit comments

Comments
 (0)