Skip to content

Commit

Permalink
Allow for POSTs larger than a few 100 bytes (#6800)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
earlephilhower authored and devyte committed Nov 24, 2019
1 parent 05d28bc commit 8f6e0dd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,20 @@ int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t s
}

// send Payload if needed
if(payload && size > 0) {
if(_client->write(&payload[0], size) != size) {
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
if (payload && size > 0) {
size_t byteswritten = 0;
const uint8_t *p = payload;
while (byteswritten < size) {
int written;
int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE);
written = _client->write(p, towrite);

This comment has been minimized.

Copy link
@AdrianEddy

AdrianEddy Nov 24, 2019

shouldn't it be write(p + bytesWritten, towrite); or am I missing something?
p pointer seems to never be updated in the loop

This comment has been minimized.

Copy link
@d-a-v

d-a-v Nov 24, 2019

Collaborator

You seem to be right, would you fix it with a pull request ?

This comment has been minimized.

Copy link
@AdrianEddy

AdrianEddy Nov 24, 2019

even though it seems obvious, I'm not comfortable making a pull request without testing it first, and I don't have the environment set up for this project. I'm just a friendly observer :)

This comment has been minimized.

Copy link
@devyte

devyte Nov 24, 2019

Collaborator

I'll do it, I should've caught this when reviewing

This comment has been minimized.

Copy link
@dirkx

dirkx via email Nov 24, 2019

if (written < 0) {
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
} else if (written == 0) {
return returnError(HTTPC_ERROR_CONNECTION_LOST);
}
byteswritten += written;
size -= written;
}
}

Expand Down

2 comments on commit 8f6e0dd

@timex-cme
Copy link

@timex-cme timex-cme commented on 8f6e0dd Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just stumbled upon another bug:

it should read
while (size > 0) {
instead of
while (byteswritten < size) {

as size is decrementing.

@timex-cme
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This problem was already found and fixed with
#7051

Please sign in to comment.