Skip to content

Commit 8b14352

Browse files
Handle HTTP Response with no content-length header
I ran into an issue with a Google Rest API which did not send back a content-length header or a transfer-encoding header. If this happens the HTTPClient gives the user no access to the response body in any way. So my solution is to set the _size variable to the remaining length of data available on _client which makes sense and works perfectly for me now.
1 parent 8ea12f8 commit 8b14352

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libraries/HTTPClient/src/HTTPClient.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,11 @@ int HTTPClient::handleHeaderResponse()
11591159

11601160
if(_size > 0) {
11611161
log_d("size: %d", _size);
1162-
}
1162+
}else{
1163+
if(_client->available() > 0){
1164+
_size = _client->available();
1165+
}
1166+
}
11631167

11641168
if(transferEncoding.length() > 0) {
11651169
log_d("Transfer-Encoding: %s", transferEncoding.c_str());

0 commit comments

Comments
 (0)