file_server: fix issue with sending last chunk

Closes: https://github.com/espressif/esp-idf/issues/4528
Closes IDFGH-2414
pull/4623/head
Mahavir Jain 2019-12-23 12:01:16 +05:30
rodzic c0d12988d3
commit 9ef8cafeca
1 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -256,15 +256,17 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Read file in chunks into the scratch buffer */ /* Read file in chunks into the scratch buffer */
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd); chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
/* Send the buffer contents as HTTP response chunk */ if (chunksize > 0) {
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) { /* Send the buffer contents as HTTP response chunk */
fclose(fd); if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
ESP_LOGE(TAG, "File sending failed!"); fclose(fd);
/* Abort sending file */ ESP_LOGE(TAG, "File sending failed!");
httpd_resp_sendstr_chunk(req, NULL); /* Abort sending file */
/* Respond with 500 Internal Server Error */ httpd_resp_sendstr_chunk(req, NULL);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file"); /* Respond with 500 Internal Server Error */
return ESP_FAIL; httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
return ESP_FAIL;
}
} }
/* Keep looping till the whole file is sent */ /* Keep looping till the whole file is sent */