|
@@ -54,27 +54,30 @@ INCBIN(wwwzip, "data/www.zip");
|
|
|
|
|
|
struct mime_type {
|
|
|
const char *ext;
|
|
|
- size_t ext_len;
|
|
|
+ uint16_t ext_len;
|
|
|
+ uint16_t flags;
|
|
|
const char *mime;
|
|
|
};
|
|
|
|
|
|
+#define MT_CHARSET 1 /* Add charset to Content-Type */
|
|
|
+
|
|
|
static const struct mime_type mime_types[] = {
|
|
|
- { ".html", 5, "text/html" },
|
|
|
- { ".xhtml", 6, "text/html" },
|
|
|
- { ".css", 4, "text/css" },
|
|
|
- { ".webp", 5, "image/webp" },
|
|
|
- { ".jpg", 4, "image/jpeg" },
|
|
|
- { ".png", 4, "image/png" },
|
|
|
- { ".ico", 4, "image/png" }, /* favicon.ico */
|
|
|
- { ".svg", 4, "image/svg+xml" },
|
|
|
- { ".pdf", 4, "application/pdf" },
|
|
|
- { ".js", 3, "text/javascript" },
|
|
|
- { ".mjs", 4, "text/javascript" },
|
|
|
- { ".json", 5, "application/json" },
|
|
|
- { ".xml", 4, "text/xml" },
|
|
|
- { ".bin", 4, "application/octet-stream" },
|
|
|
- { ".fw", 3, "application/octet-stream" },
|
|
|
- { NULL, 0, "text/plain; charset=UTF-8" } /* default */
|
|
|
+ { ".html", 5, MT_CHARSET, "text/html" },
|
|
|
+ { ".xhtml", 6, MT_CHARSET, "text/html" },
|
|
|
+ { ".css", 4, MT_CHARSET, "text/css" },
|
|
|
+ { ".webp", 5, 0, "image/webp" },
|
|
|
+ { ".jpg", 4, 0, "image/jpeg" },
|
|
|
+ { ".png", 4, 0, "image/png" },
|
|
|
+ { ".ico", 4, 0, "image/png" }, /* favicon.ico */
|
|
|
+ { ".svg", 4, MT_CHARSET, "image/svg+xml" },
|
|
|
+ { ".pdf", 4, 0, "application/pdf" },
|
|
|
+ { ".js", 3, MT_CHARSET, "text/javascript" },
|
|
|
+ { ".mjs", 4, MT_CHARSET, "text/javascript" },
|
|
|
+ { ".json", 5, MT_CHARSET, "application/json" },
|
|
|
+ { ".xml", 4, MT_CHARSET, "text/xml" },
|
|
|
+ { ".bin", 4, 0, "application/octet-stream" },
|
|
|
+ { ".fw", 3, 0, "application/octet-stream" },
|
|
|
+ { NULL, 0, MT_CHARSET, "text/plain" } /* default */
|
|
|
};
|
|
|
|
|
|
static esp_err_t httpd_static_handler(httpd_req_t *req)
|
|
@@ -174,13 +177,14 @@ static esp_err_t httpd_static_handler(httpd_req_t *req)
|
|
|
|
|
|
len = snprintf(buffer, buffer_size,
|
|
|
"HTTP/1.1 200 OK\r\n"
|
|
|
- "Content-Type: %s\r\n"
|
|
|
+ "Content-Type: %s%s\r\n"
|
|
|
"Content-Length: %u\r\n"
|
|
|
"Allow: GET, HEAD\r\n"
|
|
|
"Etag: \"%08x:%08x\"\r\n"
|
|
|
"Connection: close\r\n"
|
|
|
"\r\n",
|
|
|
mime_type->mime,
|
|
|
+ mime_type->flags & MT_CHARSET ? "; charset=\"UTF-8\"" : "",
|
|
|
fileinfo.uncompressed_size,
|
|
|
/*
|
|
|
* Hopefully the combination of date and CRC
|
|
@@ -260,7 +264,6 @@ static const httpd_uri_t uri_handlers[] = {
|
|
|
void my_httpd_stop(void)
|
|
|
{
|
|
|
if (httpd) {
|
|
|
- esp_unregister_shutdown_handler(my_httpd_stop);
|
|
|
httpd_stop(httpd);
|
|
|
httpd = NULL;
|
|
|
}
|
|
@@ -289,6 +292,5 @@ void my_httpd_start(void)
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(uri_handlers); i++)
|
|
|
httpd_register_uri_handler(httpd, &uri_handlers[i]);
|
|
|
|
|
|
- esp_register_shutdown_handler(my_httpd_stop);
|
|
|
printf("[HTTP] httpd started\n");
|
|
|
}
|