Skip to content

Commit 704b71d

Browse files
authored
Fix header parsing
fixes #4454 closes #4455
1 parent 7c05721 commit 704b71d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: libraries/HTTPClient/src/HTTPClient.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ int HTTPClient::handleHeaderResponse()
11861186

11871187
_transferEncoding = HTTPC_TE_IDENTITY;
11881188
unsigned long lastDataTime = millis();
1189+
bool firstLine = true;
11891190

11901191
while(connected()) {
11911192
size_t len = _client->available();
@@ -1197,11 +1198,12 @@ int HTTPClient::handleHeaderResponse()
11971198

11981199
log_v("RX: '%s'", headerLine.c_str());
11991200

1200-
if(headerLine.startsWith("HTTP/1.")) {
1201-
if(_canReuse) {
1201+
if(firstLine) {
1202+
if(_canReuse && headerLine.startsWith("HTTP/1.")) {
12021203
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
12031204
}
1204-
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
1205+
int codePos = headerLine.indexOf(' ') + 1;
1206+
_returnCode = headerLine.substring(codePos, headerLine.indexOf(' ', codePos)).toInt();
12051207
} else if(headerLine.indexOf(':')) {
12061208
String headerName = headerLine.substring(0, headerLine.indexOf(':'));
12071209
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);
@@ -1450,4 +1452,4 @@ bool HTTPClient::setURL(const String& url)
14501452
const String &HTTPClient::getLocation(void)
14511453
{
14521454
return _location;
1453-
}
1455+
}

0 commit comments

Comments
 (0)