| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dbf13c8 commit fe46191
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ void HttpClient::resetState() | |||
| 32 | 32 | { | |
| 33 | 33 | iState = eIdle; | |
| 34 | 34 | iStatusCode = 0; | |
| 35 | - iContentLength = 0; | ||
| 35 | + iContentLength = kNoContentLengthHeader; | ||
| 36 | 36 | iBodyLengthConsumed = 0; | |
| 37 | 37 | iContentLengthPtr = kContentLengthPrefix; | |
| 38 | 38 | iHttpResponseTimeout = kHttpResponseTimeout; | |
@@ -521,12 +521,35 @@ String HttpClient::responseBody() | |||
| 521 | 521 | ||
| 522 | 522 | if (bodyLength > 0) | |
| 523 | 523 | { | |
| 524 | - response.reserve(bodyLength); | ||
| 524 | + // try to reserve bodyLength bytes | ||
| 525 | + if (response.reserve(bodyLength) == 0) { | ||
| 526 | + // String reserve failed | ||
| 527 | + return String((const char*)NULL); | ||
| 528 | + } | ||
| 525 | 529 | } | |
| 526 | 530 | ||
| 527 | - while (available()) | ||
| 531 | + // keep on timedRead'ing, until: | ||
| 532 | + // - we have a content length: body length equals consumed or no bytes | ||
| 533 | + // available | ||
| 534 | + // - no content length: no bytes are available | ||
| 535 | + while (iBodyLengthConsumed != bodyLength) | ||
| 528 | 536 | { | |
| 529 | - response += (char)read(); | ||
| 537 | + int c = timedRead(); | ||
| 538 | + | ||
| 539 | + if (c == -1) { | ||
| 540 | + // read timed out, done | ||
| 541 | + break; | ||
| 542 | + } | ||
| 543 | + | ||
| 544 | + if (!response.concat((char)c)) { | ||
| 545 | + // adding char failed | ||
| 546 | + return String((const char*)NULL); | ||
| 547 | + } | ||
| 548 | + } | ||
| 549 | + | ||
| 550 | + if (bodyLength > 0 && (unsigned int)bodyLength != response.length()) { | ||
| 551 | + // failure, we did not read in reponse content length bytes | ||
| 552 | + return String((const char*)NULL); | ||
| 530 | 553 | } | |
| 531 | 554 | ||
| 532 | 555 | return response; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments