Problem sending chunked response in Beta3 -- fileserver.c.

DrScanlon
Posts: 11
Joined: Tue Oct 04, 2016 8:46 pm

Problem sending chunked response in Beta3 -- fileserver.c.

Postby DrScanlon » Mon Aug 19, 2019 7:52 pm

In Beta3 and ongoing development examples, in "protocols/.../file_server.c", a terminating chunk with chunksize = "0" is sent twice--once in the do-while loop and again in a closing line. This probably doesn't affect IExplorer, but Firefox (latest beta version) doesn't handle it well--frequently losing track of which images to request. This problem is also present in the later development code examples in "download_get_handler" function in fileserver.c.
  1. static esp_err_t http_resp_file(httpd_req_t *req)
  2. //static esp_err_t download_get_handler(httpd_req_t *req) in development examples
  3. {
  4. .........  
  5.       do {
  6.         /* Read file in chunks into the scratch buffer */
  7.         chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
  8.  
  9.         /* Send the buffer contents as HTTP response chunk */
  10.         //--------------------------------------------------------
  11.         // =====> Last pass will send chunksize = 0
  12.         //---------------------------------------------------------
  13.         if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
  14.             fclose(fd);
  15.             ESP_LOGE(TAG, "File sending failed!");
  16.             /* Abort sending file */
  17.             httpd_resp_sendstr_chunk(req, NULL);
  18.             /* Respond with 500 Internal Server Error */
  19.             httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
  20.             return ESP_FAIL;
  21.         }
  22.  
  23.         /* Keep looping till the whole file is sent */
  24.     } while (chunksize != 0);
  25.  
  26.     /* Close file after sending complete */
  27.     fclose(fd);
  28.     ESP_LOGI(TAG, "File sending complete");
  29.  
  30.     /* Respond with an empty chunk to signal HTTP response completion */
  31.    //---------------------------------------------------------------------------------------
  32.    // chunksize = 0  is also sent in the following line -- causes problems in FF browser
  33.    // comment it out for Firefox.
  34.    //---------------------------------------------------------------------------------------
  35.    httpd_resp_send_chunk(req, NULL, 0);
  36.     return ESP_OK;
  37. }
NOTE: Edited to correct file name from "fileserver.c" to "file_server.c"

Who is online

Users browsing this forum: No registered users and 230 guests