Skip to content

Commit fe3f8c6

Browse files
committed
http-client: fix responseHeaders list parsing
this also fixes a server regression that was breaking vMenu and other resources using GHMatti.Http in C#
1 parent 3be9e74 commit fe3f8c6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎code/components/http-client/src/HttpClient.cpp‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,19 @@ static size_t CurlHeaderInfo(char* buffer, size_t size, size_t nitems, void* use
279279
if (cd->responseHeaders)
280280
{
281281
std::string str(buffer, size * nitems);
282-
auto colonPos = str.find_first_of(": ");
282+
283+
// reset HTTP headers if we followed a Location and got a new HTTP response
284+
if (str.find("HTTP/") == 0)
285+
{
286+
(*cd->responseHeaders).clear();
287+
}
288+
289+
auto colonPos = str.find(": ");
283290

284-
(*cd->responseHeaders)[str.substr(0, colonPos)] = str.substr(colonPos + 2, str.length() - 2 - colonPos - 2);
291+
if (colonPos != std::string::npos)
292+
{
293+
(*cd->responseHeaders)[str.substr(0, colonPos)] = str.substr(colonPos + 2, str.length() - 2 - colonPos - 2);
294+
}
285295
}
286296

287297
return size * nitems;

0 commit comments

Comments
 (0)