mirror of
https://github.com/wled/WLED.git
synced 2025-07-20 09:16:31 +00:00
Use web server ContentType symbols
These were mostly PROGMEM already, but every little bit helps.
This commit is contained in:
parent
12bf04826a
commit
df6c271830
@ -434,7 +434,6 @@ void handleSerial();
|
|||||||
void updateBaudRate(uint32_t rate);
|
void updateBaudRate(uint32_t rate);
|
||||||
|
|
||||||
//wled_server.cpp
|
//wled_server.cpp
|
||||||
String getFileContentType(String &filename);
|
|
||||||
void createEditHandler(bool enable);
|
void createEditHandler(bool enable);
|
||||||
void initServer();
|
void initServer();
|
||||||
void serveMessage(AsyncWebServerRequest* request, uint16_t code, const String& headl, const String& subl="", byte optionT=255);
|
void serveMessage(AsyncWebServerRequest* request, uint16_t code, const String& headl, const String& subl="", byte optionT=255);
|
||||||
|
@ -375,6 +375,7 @@ void updateFSInfo() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
#if defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
|
||||||
// caching presets in PSRAM may prevent occasional flashes seen when HomeAssitant polls WLED
|
// caching presets in PSRAM may prevent occasional flashes seen when HomeAssitant polls WLED
|
||||||
// original idea by @akaricchi (https://github.com/Akaricchi)
|
// original idea by @akaricchi (https://github.com/Akaricchi)
|
||||||
@ -420,8 +421,7 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
|
|||||||
DEBUG_PRINT(F("WS FileRead: ")); DEBUG_PRINTLN(path);
|
DEBUG_PRINT(F("WS FileRead: ")); DEBUG_PRINTLN(path);
|
||||||
if(path.endsWith("/")) path += "index.htm";
|
if(path.endsWith("/")) path += "index.htm";
|
||||||
if(path.indexOf(F("sec")) > -1) return false;
|
if(path.indexOf(F("sec")) > -1) return false;
|
||||||
String contentType = getFileContentType(path);
|
String contentType = request->hasArg(F("download")) ? F("application/octet-stream") : contentTypeFor(path);
|
||||||
if(request->hasArg(F("download"))) contentType = F("application/octet-stream");
|
|
||||||
/*String pathWithGz = path + ".gz";
|
/*String pathWithGz = path + ".gz";
|
||||||
if(WLED_FS.exists(pathWithGz)){
|
if(WLED_FS.exists(pathWithGz)){
|
||||||
request->send(WLED_FS, pathWithGz, contentType);
|
request->send(WLED_FS, pathWithGz, contentType);
|
||||||
|
@ -1065,7 +1065,7 @@ void serveJson(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (url.indexOf("pal") > 0) {
|
else if (url.indexOf("pal") > 0) {
|
||||||
request->send_P(200, "application/json", JSON_palette_names); // contentType defined in AsyncJson-v6.h
|
request->send_P(200, FPSTR(CONTENT_TYPE_JSON), JSON_palette_names);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (url.indexOf(F("cfg")) > 0 && handleFileRead(request, F("/cfg.json"))) {
|
else if (url.indexOf(F("cfg")) > 0 && handleFileRead(request, F("/cfg.json"))) {
|
||||||
@ -1185,7 +1185,7 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient)
|
|||||||
#endif
|
#endif
|
||||||
oappend("}");
|
oappend("}");
|
||||||
if (request) {
|
if (request) {
|
||||||
request->send(200, "application/json", buffer); // contentType defined in AsyncJson-v6.h
|
request->send(200, FPSTR(CONTENT_TYPE_JSON), buffer);
|
||||||
}
|
}
|
||||||
#ifdef WLED_ENABLE_WEBSOCKETS
|
#ifdef WLED_ENABLE_WEBSOCKETS
|
||||||
else {
|
else {
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
#define DYNAMIC_JSON_DOCUMENT_SIZE 16384
|
#define DYNAMIC_JSON_DOCUMENT_SIZE 16384
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr const char* JSON_MIMETYPE = "application/json";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Json Response
|
* Json Response
|
||||||
* */
|
* */
|
||||||
@ -66,7 +64,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
|||||||
|
|
||||||
AsyncJsonResponse(JsonDocument *ref, bool isArray=false) : _jsonBuffer(1), _isValid{false} {
|
AsyncJsonResponse(JsonDocument *ref, bool isArray=false) : _jsonBuffer(1), _isValid{false} {
|
||||||
_code = 200;
|
_code = 200;
|
||||||
_contentType = JSON_MIMETYPE;
|
_contentType = FPSTR(CONTENT_TYPE_JSON);
|
||||||
if(isArray)
|
if(isArray)
|
||||||
_root = ref->to<JsonArray>();
|
_root = ref->to<JsonArray>();
|
||||||
else
|
else
|
||||||
@ -75,7 +73,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
|||||||
|
|
||||||
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
||||||
_code = 200;
|
_code = 200;
|
||||||
_contentType = JSON_MIMETYPE;
|
_contentType = FPSTR(CONTENT_TYPE_JSON);
|
||||||
if(isArray)
|
if(isArray)
|
||||||
_root = _jsonBuffer.createNestedArray();
|
_root = _jsonBuffer.createNestedArray();
|
||||||
else
|
else
|
||||||
|
@ -18,36 +18,11 @@ static const char s_unlock_ota [] PROGMEM = "Please unlock OTA in security setti
|
|||||||
static const char s_unlock_cfg [] PROGMEM = "Please unlock settings using PIN code!";
|
static const char s_unlock_cfg [] PROGMEM = "Please unlock settings using PIN code!";
|
||||||
static const char s_notimplemented[] PROGMEM = "Not implemented";
|
static const char s_notimplemented[] PROGMEM = "Not implemented";
|
||||||
static const char s_accessdenied[] PROGMEM = "Access Denied";
|
static const char s_accessdenied[] PROGMEM = "Access Denied";
|
||||||
static const char s_javascript[] PROGMEM = "application/javascript";
|
static const char* s_javascript = CONTENT_TYPE_JAVASCRIPT;
|
||||||
static const char s_json[] = "application/json"; // AsyncJson-v6.h
|
static const char* s_json = CONTENT_TYPE_JSON;
|
||||||
static const char s_html[] PROGMEM = "text/html";
|
static const char* s_html = CONTENT_TYPE_HTML;
|
||||||
static const char s_plain[] = "text/plain"; // Espalexa.h
|
static const char* s_plain = CONTENT_TYPE_PLAIN;
|
||||||
static const char s_css[] PROGMEM = "text/css";
|
static const char* s_css = CONTENT_TYPE_CSS;
|
||||||
static const char s_png[] PROGMEM = "image/png";
|
|
||||||
static const char s_gif[] PROGMEM = "image/gif";
|
|
||||||
static const char s_jpg[] PROGMEM = "image/jpeg";
|
|
||||||
static const char s_ico[] PROGMEM = "image/x-icon";
|
|
||||||
//static const char s_xml[] PROGMEM = "text/xml";
|
|
||||||
//static const char s_pdf[] PROGMEM = "application/x-pdf";
|
|
||||||
//static const char s_zip[] PROGMEM = "application/x-zip";
|
|
||||||
//static const char s_gz[] PROGMEM = "application/x-gzip";
|
|
||||||
|
|
||||||
String getFileContentType(String &filename) {
|
|
||||||
if (filename.endsWith(F(".htm"))) return FPSTR(s_html);
|
|
||||||
else if (filename.endsWith(F(".html"))) return FPSTR(s_html);
|
|
||||||
else if (filename.endsWith(F(".css"))) return FPSTR(s_css);
|
|
||||||
else if (filename.endsWith(F(".js"))) return FPSTR(s_javascript);
|
|
||||||
else if (filename.endsWith(F(".json"))) return s_json;
|
|
||||||
else if (filename.endsWith(F(".png"))) return FPSTR(s_png);
|
|
||||||
else if (filename.endsWith(F(".gif"))) return FPSTR(s_gif);
|
|
||||||
else if (filename.endsWith(F(".jpg"))) return FPSTR(s_jpg);
|
|
||||||
else if (filename.endsWith(F(".ico"))) return FPSTR(s_ico);
|
|
||||||
// else if (filename.endsWith(F(".xml"))) return FPSTR(s_xml);
|
|
||||||
// else if (filename.endsWith(F(".pdf"))) return FPSTR(s_pdf);
|
|
||||||
// else if (filename.endsWith(F(".zip"))) return FPSTR(s_zip);
|
|
||||||
// else if (filename.endsWith(F(".gz"))) return FPSTR(s_gz);
|
|
||||||
return s_plain;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Is this an IP?
|
//Is this an IP?
|
||||||
static bool isIp(String str) {
|
static bool isIp(String str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user