Fix header parsing

fixes #4454

closes #4455
This commit is contained in:
Me No Dev 2020-11-02 20:10:22 +02:00 committed by GitHub
parent 7c0572172c
commit 704b71dabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1186,6 +1186,7 @@ int HTTPClient::handleHeaderResponse()
_transferEncoding = HTTPC_TE_IDENTITY; _transferEncoding = HTTPC_TE_IDENTITY;
unsigned long lastDataTime = millis(); unsigned long lastDataTime = millis();
bool firstLine = true;
while(connected()) { while(connected()) {
size_t len = _client->available(); size_t len = _client->available();
@ -1197,11 +1198,12 @@ int HTTPClient::handleHeaderResponse()
log_v("RX: '%s'", headerLine.c_str()); log_v("RX: '%s'", headerLine.c_str());
if(headerLine.startsWith("HTTP/1.")) { if(firstLine) {
if(_canReuse) { if(_canReuse && headerLine.startsWith("HTTP/1.")) {
_canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0'); _canReuse = (headerLine[sizeof "HTTP/1." - 1] != '0');
} }
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt(); int codePos = headerLine.indexOf(' ') + 1;
_returnCode = headerLine.substring(codePos, headerLine.indexOf(' ', codePos)).toInt();
} else if(headerLine.indexOf(':')) { } else if(headerLine.indexOf(':')) {
String headerName = headerLine.substring(0, headerLine.indexOf(':')); String headerName = headerLine.substring(0, headerLine.indexOf(':'));
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1); String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);