-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Update HTTPClient.cpp to send big payload #7638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -604,6 +604,9 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) | |
|
||
if(payload && size > 0) { | ||
addHeader(F("Content-Length"), String(size)); | ||
} else { | ||
// force 0 content length for redirect request | ||
addHeader(F("Content-Length"), String("0")); | ||
} | ||
|
||
// add cookies to header, if present | ||
|
@@ -619,10 +622,21 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) | |
|
||
// send Payload if needed | ||
if(payload && size > 0) { | ||
if(_client->write(&payload[0], size) != size) { | ||
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); | ||
|
||
// this will fail for big payload | ||
// if(_client->write(&payload[0], size) != size) { | ||
// return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); | ||
// } | ||
|
||
// send the payload per 1000 bytes | ||
log_d("Sending %u byte ...\n", size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like your PR is introducing a mix of TAB and SPACE characters resulting in a jumbled mess of formatting. Can you please reformat your additional code to match the existing formatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @atanisoft Fixed. Please kindly check it. Thank you. |
||
size_t sent_bytes = 0; | ||
for (size_t id_data = 0; id_data < size; id_data+=1000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of a for loop using fixed sizes for chunks, please consider a loop similar to below (note this is not tested):
Note that there is ZERO guarantee that the write call will send the full block size you request it to send thus you must check that it actually sent data and only then move the data starting point. The check for negative sent byte count is to check for sending errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @atanisoft Fixed. Please kindly check it. Thank you. |
||
{ | ||
sent_bytes = _client->write(&payload[id_data], ((id_data+1000)<=size)?1000:(size-id_data)); | ||
log_d("Sent %u bytes\n", sent_bytes); | ||
} | ||
} | ||
} | ||
|
||
code = handleHeaderResponse(); | ||
log_d("sendRequest code=%d\n", code); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of leaving the old code in comments, it would be better to simply drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atanisoft Fixed. Please kindly check it. Thank you.