فهرست منبع

Avoid secondary HTTP errors after client disconnect

SybexXx 2 روز پیش
والد
کامیت
e5acc4f280
1فایلهای تغییر یافته به همراه9 افزوده شده و 8 حذف شده
  1. 9 8
      code/components/jomjol_fileserver_ota/server_help.cpp

+ 9 - 8
code/components/jomjol_fileserver_ota/server_help.cpp

@@ -108,17 +108,18 @@ esp_err_t send_file(httpd_req_t *req, std::string filename)
         chunksize = fread(chunk, 1, SERVER_HELPER_SCRATCH_BUFSIZE, fd);
 
         /* Send the buffer contents as HTTP response chunk */
-        if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK)
+        const esp_err_t sendResult = httpd_resp_send_chunk(req, chunk, chunksize);
+        if (sendResult != ESP_OK)
         {
             fclose(fd);
-            ESP_LOGE(TAG, "File sending failed!");
-
-            /* Abort sending file */
-            httpd_resp_sendstr_chunk(req, NULL);
-
-            /* Respond with 500 Internal Server Error */
-            httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file");
 
+            // The response headers/body may already have been sent. A failed
+            // chunk send usually means the peer closed/reset the connection;
+            // trying to send a final chunk or a second HTTP 500 response on
+            // that socket only creates secondary errors and cannot reach the
+            // client.
+            ESP_LOGW(TAG, "File transfer interrupted for %s (send error %d)",
+                     filename.c_str(), static_cast<int>(sendResult));
             return ESP_FAIL;
         }