Skip to content

Commit 53669c0

Browse files
authored
fix merge by hand esp8266#2
1 parent 89a5f5e commit 53669c0

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -1258,3 +1258,60 @@ int HTTPClient::returnError(int error)
12581258
}
12591259
return error;
12601260
}
1261+
1262+
1263+
/**
1264+
* Read header of next chunk in HTTP response using chunked encoding
1265+
* @param blocking bool whether this method is allowed to block
1266+
* @return boolean value indicating whether a complete header could be read
1267+
*/
1268+
bool HTTPClient::readChunkHeader(bool blocking)
1269+
{
1270+
if (blocking) {
1271+
_chunkHeader += _client->readStringUntil('\n');
1272+
if (_chunkHeader.length() == 0) {
1273+
return false;
1274+
}
1275+
} else {
1276+
while (_client->available() && !_chunkHeader.endsWith("\n")) {
1277+
_chunkHeader += (char) _client->read();
1278+
}
1279+
if (!_chunkHeader.endsWith("\n")) {
1280+
return false;
1281+
}
1282+
}
1283+
1284+
// read size of chunk
1285+
_chunkLen = (uint32_t) strtol((const char *) _chunkHeader.c_str(), NULL,
1286+
16);
1287+
1288+
_chunkOffset = 0;
1289+
return true;
1290+
}
1291+
1292+
/**
1293+
* Read trailer of current chunk in HTTP response using chunked encoding
1294+
* @param blocking bool whether this method is allowed to block
1295+
* @return boolean value indicating whether the complete trailer could be read
1296+
*/
1297+
bool HTTPClient::readChunkTrailer(bool blocking)
1298+
{
1299+
uint8_t buf[2];
1300+
1301+
if (blocking || (_client->available() >= 2)) {
1302+
auto trailing_seq_len = _client->readBytes((uint8_t *) buf, 2);
1303+
1304+
if (trailing_seq_len != 2 || buf[0] != '\r' || buf[1] != '\n') {
1305+
return false;
1306+
} else {
1307+
/* Clear _chunkHeader to indicate that the current chunk has been
1308+
* completely read, and reset _chunkLen to indicate that the next
1309+
* chunk header has not been read yet. */
1310+
_chunkHeader.clear();
1311+
_chunkLen = 0;
1312+
return true;
1313+
}
1314+
} else {
1315+
return false;
1316+
}
1317+
}

0 commit comments

Comments
 (0)