consolidate test-ip definition, added missing Access-Control-Allow-Origin (#1741)

Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
CaCO3
2023-01-02 14:31:00 +01:00
committed by GitHub
parent 485e55e0b8
commit 4d823b354f
27 changed files with 266 additions and 222 deletions

View File

@@ -212,6 +212,8 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
return ESP_FAIL;
}
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* Send HTML file header */
httpd_resp_sendstr_chunk(req, "<!DOCTYPE html><html><body>");
@@ -344,12 +346,6 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file)
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
// Since the log file is still could open for writing, we need to close it first
LogFile.CloseLogFileAppendHandle();
fd = fopen(currentfilename.c_str(), "r");
if (!fd) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read existing file: " + std::string(filepath) +"!");
@@ -434,6 +430,8 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file)
ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath);
// Since the log file is still could open for writing, we need to close it first
LogFile.CloseLogFileAppendHandle();
fd = fopen(currentfilename.c_str(), "r");
if (!fd) {
@@ -614,6 +612,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
FILE *fd = NULL;
struct stat file_stat;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* Skip leading "/upload" from URI to get filename */
/* Note sizeof() counts NULL termination hence the -1 */
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
@@ -764,6 +764,8 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
std::string directory;
std::string zw;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
ESP_LOGD(TAG, "Query: %s", _query);

View File

@@ -666,7 +666,7 @@ esp_err_t handler_reboot(httpd_req_t *req)
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot");
ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!");
const char* resp_str = "<body style='font-family: arial'> <h3 id=t></h3></body><script>var h='Rebooting!<br>The page will automatically reload in around 25..60s<br>(in case of a firmware update it can take up to 180s).<br>'; document.getElementById('t').innerHTML=h; setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h; fetch('/reboot_page.html',{mode: 'no-cors'}).then(r=>{parent.location.href=('/index.html');})}, 1000);</script>";
const char* resp_str = "<body style='font-family: arial'> <h3 id=t></h3></body><script>var h='Rebooting!<br>The page will automatically reload in around 25..60s<br>(in case of a firmware update it can take up to 180s).<br>'; document.getElementById('t').innerHTML=h; setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h; fetch('reboot_page.html',{mode: 'no-cors'}).then(r=>{parent.location.href=('index.html');})}, 1000);</script>";
httpd_resp_send(req, resp_str, strlen(resp_str));
doReboot();

View File

@@ -147,6 +147,7 @@ esp_err_t handler_init(httpd_req_t *req)
doInit();
resp_str = "Init done<br>";
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -179,6 +180,8 @@ esp_err_t handler_flow_start(httpd_req_t *req) {
httpd_resp_send(req, resp_str, strlen(resp_str));
}
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -421,6 +424,8 @@ esp_err_t handler_editflow(httpd_req_t *req)
char _valuechar[30];
string _task;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)