Skip to content

Commit d3ea904

Browse files
committed
Prepare to refactor readMessage(std::string)
1 parent b05ce85 commit d3ea904

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/http/http.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, std
430430
if(!sendMessage(method, endUrl, data, content_type))
431431
return false;
432432

433-
if(!readMessage(output)){
433+
Result readResult;
434+
readMessage(output, readResult);
435+
if(readResult != OK) {
434436

435437
// Clear ouput in case we didn't get the full response.
436438
if(!output.empty())
@@ -458,21 +460,14 @@ bool HTTP::request(const char* method, const char* endUrl, const char* data, std
458460
}
459461

460462
// Whole process to read the response from HTTP server.
461-
bool HTTP::readMessage(std::string& output) {
463+
void HTTP::readMessage(std::string& output, Result& result) {
462464

463465
// Need to loop (recursion may fail because pile up over the stack for large requests.
464466
size_t contentLength = 0;
465467
bool isChunked = false;
466-
Result readResult;
467468
do {
468-
readMessage(output, contentLength, isChunked, readResult);
469-
} while(readResult == MORE_DATA);
470-
471-
if(readResult == OK)
472-
return true;
473-
474-
// If not, there was an error somewhere.
475-
return false;
469+
readMessage(output, contentLength, isChunked, result);
470+
} while(result == MORE_DATA);
476471
}
477472

478473
// Wait with select then start to read the message.

src/http/http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class HTTP {
115115
void disconnect();
116116

117117
/// Whole process to read the response from HTTP server.
118-
bool readMessage(std::string& output);
118+
void readMessage(std::string& output, Result& result);
119119

120120
/// Wait with select then start to read the message.
121121
unsigned int readMessage(std::string& output, size_t& contentLength, bool& isChunked, Result& result);

0 commit comments

Comments
 (0)