Skip to content

Commit 6ed7dfe

Browse files
committed
improve handling of non http servers
1 parent be91d96 commit 6ed7dfe

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

libraries/ESP8266httpClient/src/ESP8266httpClient.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ int httpClient::handleHeaderResponse() {
386386
return HTTPC_ERROR_NOT_CONNECTED;
387387
}
388388

389+
_returnCode = -1;
390+
_size = -1;
391+
389392
while(connected()) {
390393
size_t len = _tcp->available();
391394
if(len > 0) {
@@ -421,7 +424,12 @@ int httpClient::handleHeaderResponse() {
421424
if(_size) {
422425
DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] size: %d\n", _size);
423426
}
424-
return _returnCode;
427+
if(_returnCode) {
428+
return _returnCode;
429+
} else {
430+
DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] Remote host is not an HTTP Server!");
431+
return HTTPC_ERROR_NO_HTTP_SERVER;
432+
}
425433
}
426434

427435
} else {

libraries/ESP8266httpClient/src/ESP8266httpClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define HTTPC_ERROR_NOT_CONNECTED (-4)
4141
#define HTTPC_ERROR_CONNECTION_LOST (-5)
4242
#define HTTPC_ERROR_NO_STREAM (-6)
43+
#define HTTPC_ERROR_NO_HTTP_SERVER (-7)
4344

4445

4546
class httpClient {

0 commit comments

Comments
 (0)