Skip to content

Commit 3cec5d7

Browse files
committed
[iec] enhance ML HTTP client streaming
1 parent da676c8 commit 3cec5d7

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

lib/meatloaf/network/http.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,13 @@ bool MeatHttpClient::seek(uint32_t pos) {
278278
return true;
279279

280280
if(isFriendlySkipper) {
281-
esp_http_client_close(_http);
281+
282+
if (_is_open) {
283+
// Read to end of the stream
284+
//Debug_printv("Skipping to end!");
285+
char c[255];
286+
while( esp_http_client_read(_http, c, 255) );
287+
}
282288

283289
bool op = processRedirectsAndOpen(pos);
284290

@@ -395,27 +401,26 @@ int MeatHttpClient::openAndFetchHeaders(esp_http_client_method_t meth, int resum
395401

396402
if(resume > 0) {
397403
char str[40];
398-
snprintf(str, sizeof str, "bytes=%lu-", (unsigned long)resume);
404+
snprintf(str, sizeof str, "bytes=%lu-%lu", (unsigned long)resume, ((unsigned long)resume + HTTP_BLOCK_SIZE));
399405
esp_http_client_set_header(_http, "range", str);
400406
}
401407

402408
//Debug_printv("--- PRE OPEN");
403-
esp_err_t initOk = esp_http_client_open(_http, 0); // or open? It's not entirely clear...
404-
405-
if(initOk == ESP_FAIL)
406-
return 0;
409+
esp_err_t rc = esp_http_client_open(_http, 0); // or open? It's not entirely clear...
407410

408-
//Debug_printv("--- PRE FETCH HEADERS");
411+
if (rc == ESP_OK)
412+
{
413+
//Debug_printv("--- PRE FETCH HEADERS");
409414

410-
int64_t lengthResp = esp_http_client_fetch_headers(_http);
411-
if(_size == -1 && lengthResp > 0) {
412-
// only if we aren't chunked!
413-
_size = lengthResp;
414-
_position = 0;
415+
int64_t lengthResp = esp_http_client_fetch_headers(_http);
416+
if(_size == -1 && lengthResp > 0) {
417+
// only if we aren't chunked!
418+
_size = lengthResp;
419+
_position = 0;
420+
}
415421
}
416422

417423
//Debug_printv("--- PRE GET STATUS CODE");
418-
419424
return esp_http_client_get_status_code(_http);
420425
}
421426

0 commit comments

Comments
 (0)