Skip to content

Commit c7a19f5

Browse files
authored
fix + enforce testing http code
per @earlephilhower review
1 parent 1107d2c commit c7a19f5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,10 @@ int HTTPClient::handleHeaderResponse()
13511351

13521352
if (headerLine.startsWith(F("HTTP/1."))) {
13531353

1354-
_canReuse = _canReuse && (headerLine[sizeof "HTTP/1." - 1] != '0');
1355-
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
1356-
_canReuse = _canReuse && (_returnCode != '0');
1354+
constexpr auto httpVersionIdx = sizeof "HTTP/1." - 1;
1355+
_canReuse = _canReuse && (headerLine[httpVersionIdx] != '0');
1356+
_returnCode = headerLine.substring(httpVersionIdx + 2, headerLine.indexOf(' ', httpVersionIdx + 2)).toInt();
1357+
_canReuse = _canReuse && (_returnCode > 0) && (_returnCode < 500);
13571358

13581359
} else if ((headerSeparator = headerLine.indexOf(':')) > 0) {
13591360
String headerName = headerLine.substring(0, headerSeparator);

0 commit comments

Comments
 (0)