fixed mangle woff2 files

This commit is contained in:
Bogdan Pilyugin 2022-08-25 16:10:08 +02:00
parent d22992654b
commit 4baa916c90
2 changed files with 17 additions and 7 deletions

View File

@ -27,13 +27,13 @@ static const char *TAG = "HTTPServerPost";
#define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN) #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
const char url_eth_settings[] = "sys/set_eth.html"; const char url_eth_settings[] = "set_eth.html";
const char url_wifi_settings[] = "sys/set_wifi.html"; const char url_wifi_settings[] = "set_wifi.html";
const char url_gprs_settings[] = "sys/set_gprs.html"; const char url_gprs_settings[] = "set_gprs.html";
const char url_mqtt_settings[] = "sys/set_mqtt.html"; const char url_mqtt_settings[] = "set_mqtt.html";
const char url_sys_settings[] = "sys/set_sys.html"; const char url_sys_settings[] = "set_sys.html";
const char url_time_settings[] = "sys/set_time.html"; const char url_time_settings[] = "set_time.html";
const char url_reboot[] = "sys/reboot.html"; const char url_reboot[] = "reboot.html";
static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData); static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData);

View File

@ -124,6 +124,10 @@ static esp_err_t set_content_type_from_file(httpd_req_t *req,
{ {
return httpd_resp_set_type(req, "text/css"); return httpd_resp_set_type(req, "text/css");
} }
else if (IS_FILE_EXT(filename, ".woff2"))
{
return httpd_resp_set_type(req, "font/woff2");
}
/* This is a limited set only */ /* This is a limited set only */
/* For any other type always set as plain text */ /* For any other type always set as plain text */
return httpd_resp_set_type(req, "text/plain"); return httpd_resp_set_type(req, "text/plain");
@ -305,12 +309,18 @@ static esp_err_t GETHandler(httpd_req_t *req)
espfs_fclose(file); espfs_fclose(file);
return ESP_FAIL; return ESP_FAIL;
} }
if (memmem(buf, 3, GZIP_SIGN, 3)) if (memmem(buf, 3, GZIP_SIGN, 3))
{ {
httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
httpd_resp_set_hdr(req, "Cache-Control", "max-age=600"); httpd_resp_set_hdr(req, "Cache-Control", "max-age=600");
isCompressed = true; isCompressed = true;
} }
//prevent mangle compressed font files
if (IS_FILE_EXT(filename, ".woff2"))
isCompressed = true;
int pt = 0; int pt = 0;
do do
{ {