Skip to content

Commit

Permalink
Fix persistance issue found, see ESP8266 issue #6152 (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen88 authored and me-no-dev committed Jun 5, 2019
1 parent 89feacb commit 7d78247
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,8 @@ int HTTPClient::handleHeaderResponse()
return HTTPC_ERROR_NOT_CONNECTED;
}

_canReuse = !_useHTTP10;

String transferEncoding;
_returnCode = -1;
_size = -1;
Expand All @@ -1098,6 +1100,7 @@ int HTTPClient::handleHeaderResponse()

if(headerLine.startsWith("HTTP/1.")) {
_returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
_canReuse = (_returnCode != '0');

This comment has been minimized.

Copy link
@ThomasWaldmann

ThomasWaldmann May 20, 2020

this looks broken to me:

  • _returnCode is initalized above to -1 (int)
  • in 1102 a new int (result of .toInt() call) is assigned
  • in 1103 the int is compared to a character '0' (the latter can be interpreted as int and its value is 0x30 == 48 then)
  • http return codes are usually 1xx, 2xx, 3xx, 4xx, 5xx, there is no '0' or 48.

am i misunderstanding something or is this broken?

This comment has been minimized.

Copy link
@earlephilhower

earlephilhower May 20, 2020

Contributor

Yes, it is busted (in a couple other spots, too).

Please see esp8266/Arduino#6476 where we had add'l changes. I'm sure you can port the patch to ESP32 almost trivially...

This comment has been minimized.

Copy link
@ThomasWaldmann

ThomasWaldmann May 20, 2020

Ah, interesting, that is rather recent, thanks! I only found another older subsequent fix.

} else if(headerLine.indexOf(':')) {
String headerName = headerLine.substring(0, headerLine.indexOf(':'));
String headerValue = headerLine.substring(headerLine.indexOf(':') + 1);
Expand Down
2 changes: 1 addition & 1 deletion libraries/HTTPClient/src/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class HTTPClient
String _host;
uint16_t _port = 0;
int32_t _connectTimeout = -1;
bool _reuse = false;
bool _reuse = true;
uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
bool _useHTTP10 = false;
bool _secure = false;
Expand Down

0 comments on commit 7d78247

Please sign in to comment.