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

fixed buggy reading of http body from stream resulting in incomplete … #1349

Merged
merged 1 commit into from Mar 19, 2018

Conversation

verybadsoldier
Copy link
Contributor

…body returned when size >1024 byte

For me sending HTTP POST requests with bodies greater than 1024 byte led to bodies cut to 1024.

@@ -157,7 +157,7 @@ String HttpRequest::getBody()
if(stream->available() != -1 && stream->getStreamType() == eSST_Memory) {
MemoryDataStream *memory = (MemoryDataStream *)stream;
char buf[1024];
for(int i=0; i< stream->available(); i += 1024) {
while(stream->available()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comparison for the value to be bigger than 0?

@slaff
Copy link
Contributor

slaff commented Mar 19, 2018

For me sending HTTP POST requests with bodies greater than 1024 byte led to bodies cut to 1024.

@verybadsoldier Can you paste in the comments also a sample application that demonstrates the issue?

@slaff slaff added this to the 3.5.2 milestone Mar 19, 2018
@verybadsoldier
Copy link
Contributor Author

I don't have a minimal example at hand so I can only refer to our project where this problem popped up after upgrading from 3.5.0 to 3.5.1:
https://github.com/verybadsoldier/esp_rgbww_firmware/blob/master/app/webserver.cpp#L264

When doing a HTTP POST with a body length of, for example, 1123 bytes then the function request.getBody() returns a String object with a length of only 1024 bytes.

According to my understanding, inside of the function HttpRequest::getBody() a call to stream->available() will return the number of bytes currently left for processing. So the loop will start, consume the first 1024 bytes, so variable i will be 1024. So when checking the next for-loop iteration then i will be 1024 but a call to stream->available() will only return 99 (1123 - 1024) and the loop will exit, leaving the remaining 99 bytes unprocessed in the stream.

Also added > 0.

@slaff slaff merged commit 958d41e into SmingHub:develop Mar 19, 2018
@slaff
Copy link
Contributor

slaff commented Mar 19, 2018

Great, thanks!

@slaff slaff removed the 3 - Review label Mar 19, 2018
@verybadsoldier verybadsoldier deleted the fix/http-body-gt1024 branch March 19, 2018 16:04
@slaff slaff mentioned this pull request Apr 24, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants