ソースを参照

Merge pull request #4167 from alfeg/fix/http-duplicate-chunk-terminator

fix(http): don't terminate HTTP responses twice
SybexXx 1 ヶ月 前
親
コミット
0b4c78667f

+ 2 - 8
code/components/jomjol_fileserver_ota/server_file.cpp

@@ -421,15 +421,12 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file)
             return ESP_FAIL;
         }
 
-        /* Keep looping till the whole file is sent */
+        /* Keep looping till the whole file is sent (the last, empty chunk terminates the response) */
     } while (chunksize != 0);
 
     /* Close file after sending complete */
     fclose(fd);
     ESP_LOGI(TAG, "File sending complete");
-
-    /* Respond with an empty chunk to signal HTTP response completion */
-    httpd_resp_send_chunk(req, NULL, 0);
     return ESP_OK;
 }
 
@@ -515,15 +512,12 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file)
             return ESP_FAIL;
         }
 
-        /* Keep looping till the whole file is sent */
+        /* Keep looping till the whole file is sent (the last, empty chunk terminates the response) */
     } while (chunksize != 0);
 
     /* Close file after sending complete */
     fclose(fd);
     ESP_LOGD(TAG, "File sending complete");
-
-    /* Respond with an empty chunk to signal HTTP response completion */
-    httpd_resp_send_chunk(req, NULL, 0);
     return ESP_OK;
 }
 

+ 0 - 5
code/components/jomjol_fileserver_ota/server_ota.cpp

@@ -385,8 +385,6 @@ esp_err_t handler_ota_update(httpd_req_t *req)
 
         httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
         httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
-        /* Respond with an empty chunk to signal HTTP response completion */
-        httpd_resp_send_chunk(req, NULL, 0);
 
         ESP_LOGD(TAG, "Done empty directory /firmware");
         return ESP_OK;
@@ -448,7 +446,6 @@ esp_err_t handler_ota_update(httpd_req_t *req)
         unzip_file(in, out + "/");
         std::string zw = "Web Interface Update Successfull!\nNo reboot necessary";
         httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
-        httpd_resp_sendstr_chunk(req, NULL);
         return ESP_OK;
     }
 
@@ -474,14 +471,12 @@ esp_err_t handler_ota_update(httpd_req_t *req)
         std::string zw = "file deleted\n";
         ESP_LOGD(TAG, "%s", zw.c_str());
         httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
-        httpd_resp_send_chunk(req, NULL, 0);
         return ESP_OK;
     }
 
     std::string zw = "ota without parameter - should not be the case!";
     httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
     httpd_resp_send(req, zw.c_str(), strlen(zw.c_str()));
-    httpd_resp_send_chunk(req, NULL, 0);
 
     LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "ota without parameter - should not be the case!");
 

+ 0 - 3
code/components/jomjol_flowcontroll/MainFlowControl.cpp

@@ -1514,9 +1514,6 @@ esp_err_t handler_current_date(httpd_req_t *req)
     httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
     httpd_resp_send(req, formatedDateAndTime.c_str(), formatedDateAndTime.length());
 
-    /* Respond with an empty chunk to signal HTTP response completion */
-    httpd_resp_sendstr_chunk(req, NULL);
-
 #ifdef DEBUG_DETAIL_ON
     LogFile.WriteHeapInfo("handler_uptime - End");
 #endif

+ 3 - 10
code/main/server_main.cpp

@@ -290,9 +290,7 @@ esp_err_t hello_main_handler(httpd_req_t *req)
         return ESP_FAIL;
     }
 
-    res = send_file(req, filetosend);
-    /* Respond with an empty chunk to signal HTTP response completion */
-    httpd_resp_send_chunk(req, NULL, 0);
+    res = send_file(req, filetosend);   // send_file() already terminates the chunked response
 
     if (res != ESP_OK)
         return res;
@@ -324,13 +322,8 @@ esp_err_t img_tmp_handler(httpd_req_t *req)
     filetosend = filetosend + "/img_tmp/" + std::string(filename);
     ESP_LOGD(TAG, "File to upload: %s", filetosend.c_str());
 
-    esp_err_t res = send_file(req, filetosend); 
-    if (res != ESP_OK)
-        return res;
-
-    /* Respond with an empty chunk to signal HTTP response completion */
-    httpd_resp_send_chunk(req, NULL, 0);
-    return ESP_OK;
+    // send_file() already terminates the chunked response
+    return send_file(req, filetosend);
 }