elnormous / elnormous/HTTPRequest

A fix for receive response

Open
#77 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
970
Forks
200
PR merge metrics
No merged PRs in 30d

Description

Fix problem when receive partly response packet:

diff --git a/thirdparty/HTTPRequest/include/HTTPRequest.hpp b/thirdparty/HTTPRequest/include/HTTPRequest.hpp
index c446e216..1c559632 100644
--- a/thirdparty/HTTPRequest/include/HTTPRequest.hpp
+++ b/thirdparty/HTTPRequest/include/HTTPRequest.hpp
@@ -1198,6 +1198,7 @@ namespace http
bool removeCrlfAfterChunk = false;

// read the response
+ int header_recv_times = 0;
for (;;)
{
const auto size = socket.recv(tempBuffer.data(), tempBuffer.size(),
@@ -1213,7 +1214,16 @@ namespace http
// Empty line indicates the end of the header section (RFC 7230, 2.1. Client/Server Messaging)
const auto endIterator = std::search(responseData.cbegin(), responseData.cend(),
headerEnd.cbegin(), headerEnd.cend());
- if (endIterator == responseData.cend()) break; // two consecutive CRLFs not found
+ if (endIterator == responseData.cend())
+ {
+ if (header_recv_times < 3)
+ {
+ header_recv_times++;
+ continue;
+ }
+ else
+ break; // two consecutive CRLFs not found
+ }

const auto headerBeginIterator = responseData.cbegin();

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.