Skip to content
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

ESP8266HTTPClient issue in library #7049

Closed
byq13 opened this issue Jan 31, 2020 · 3 comments · Fixed by #7051
Closed

ESP8266HTTPClient issue in library #7049

byq13 opened this issue Jan 31, 2020 · 3 comments · Fixed by #7051
Milestone

Comments

@byq13
Copy link

byq13 commented Jan 31, 2020

Message bigger than 1460 bytes can't be send.
ESP8266HTTPClient.CPP

Problem is in:

Function: int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t size)

// send Payload if needed
        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 + bytesWritten, towrite);
                if (written < 0) {
                     return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
                } else if (written == 0) {
                     return returnError(HTTPC_ERROR_CONNECTION_LOST);
                }
                bytesWritten += written;
                size -= written;
            }
        }

Problematic is:
size -= written; - because SIZE is subtracting every loop and then in WHILE is compared to overal bytes sent. Only first chunk 1460 bytes can be send.

Solution:
size -= written; - this should be erased.
bytesWritten += written; - this is enough for this function.

Proper code is:

// send Payload if needed
        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 + bytesWritten, towrite);
                if (written < 0) {
                     return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
                } else if (written == 0) {
                     return returnError(HTTPC_ERROR_CONNECTION_LOST);
                }
                bytesWritten += written;
                //size -= written;
            }
        }
@d-a-v
Copy link
Collaborator

d-a-v commented Jan 31, 2020

That is true.
Would you like to make the fix ?

@d-a-v d-a-v added this to the 2.7.0 milestone Jan 31, 2020
@byq13
Copy link
Author

byq13 commented Jan 31, 2020

I am not familiar with Github. I am using is as a forum :)
Please if it is not big problem for you, could you fix it?

@byq13 byq13 closed this as completed Jan 31, 2020
@d-a-v
Copy link
Collaborator

d-a-v commented Jan 31, 2020

Someone (a maintainer or any other volunteer) will address this issue very soon.
Please leave it opened, it will be closed when fixed.
This is not a github process but a git process, if you are familiar with the git tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants