Browse Source

web: image length is a compile time constant

pull/2525/head
Maxim Prokhorov 1 year ago
parent
commit
2c728074f9
12 changed files with 22 additions and 30 deletions
  1. +1
    -2
      code/espurna/static/index.all.html.gz.h
  2. +1
    -2
      code/espurna/static/index.curtain.html.gz.h
  3. +1
    -2
      code/espurna/static/index.garland.html.gz.h
  4. +1
    -2
      code/espurna/static/index.light.html.gz.h
  5. +1
    -2
      code/espurna/static/index.lightfox.html.gz.h
  6. +1
    -2
      code/espurna/static/index.rfbridge.html.gz.h
  7. +1
    -2
      code/espurna/static/index.rfm69.html.gz.h
  8. +1
    -2
      code/espurna/static/index.sensor.html.gz.h
  9. +1
    -2
      code/espurna/static/index.small.html.gz.h
  10. +1
    -2
      code/espurna/static/index.thermostat.html.gz.h
  11. +11
    -8
      code/espurna/web.cpp
  12. +1
    -2
      code/gulpfile.js

+ 1
- 2
code/espurna/static/index.all.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 45486
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xeb,0x7a,0xdb,0x46,0xd2,0x30,0xf8,0x7f,
0xae,0x82,0x82,0x13,0x85,0xb0,0x40,0xf0,0x24,0x51,0x12,0x69,0x58,0x9f,0x2c,0xdb,0x89,0x33,0x3e,0xc5,
0x72,0x26,0x99,0x91,0x35,0x31,0x44,0x82,0x22,0x62,0x10,0xe0,0x00,0xa0,0x0e,0x96,0xf8,0x3d,0xcf,0x5e,


+ 1
- 2
code/espurna/static/index.curtain.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 28613
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0x48,0xd2,0x28,0xf8,0xbf,
0x9f,0x02,0x86,0xbb,0x6d,0xb2,0x0d,0xae,0xda,0x49,0x53,0xfe,0xa8,0xc5,0xb6,0xaa,0x6c,0x49,0xb6,0xe4,
0xaa,0x72,0xb9,0xf4,0x75,0x81,0x64,0x92,0x44,0x99,0x04,0x58,0x00,0x28,0x59,0x96,0xf9,0x9d,0x7b,0x1f,


+ 1
- 2
code/espurna/static/index.garland.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 27758
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0x48,0xb2,0x30,0xf8,0xbf,
0x9f,0x02,0x46,0x75,0xdb,0x64,0x1b,0x5c,0xb5,0x9a,0xb4,0xe4,0x4b,0x2d,0xb6,0x55,0x65,0x4b,0xb2,0x25,
0xd7,0xe6,0xd2,0xad,0x02,0xc9,0xa4,0x88,0x12,0x08,0xb0,0x01,0x50,0x8b,0x65,0xde,0x33,0xf3,0x08,0xf3,


+ 1
- 2
code/espurna/static/index.light.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 39424
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0x48,0xd2,0x28,0xf8,0xbf,
0x9f,0x82,0x82,0xab,0x54,0x84,0x05,0x82,0x9b,0x48,0x49,0xa4,0x61,0x5e,0x59,0xb6,0xcb,0xae,0xf6,0x56,
0x96,0xaa,0xab,0xaa,0x65,0x75,0x15,0x44,0x82,0x24,0x6c,0x10,0x60,0x01,0xa0,0x16,0x53,0xbc,0xe7,0xdc,


+ 1
- 2
code/espurna/static/index.lightfox.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 27811
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0xd6,0xb2,0x30,0xf8,0xff,
0x3c,0x05,0x0c,0xe7,0xd8,0xe4,0x31,0x38,0x6a,0x26,0x4d,0xf9,0x52,0x83,0x2d,0x25,0xb6,0x24,0x5b,0x72,
0x1c,0xc7,0xd1,0x4d,0x40,0x12,0x24,0x11,0x81,0x00,0x03,0x80,0x1a,0x2c,0xf3,0xae,0xee,0x47,0xe8,0x27,


+ 1
- 2
code/espurna/static/index.rfbridge.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 28461
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0x48,0xb2,0x30,0xf8,0xbf,
0x9f,0x02,0x86,0xbb,0x6d,0xb2,0x0d,0xae,0x5a,0x4d,0x5a,0xf2,0xa5,0x16,0xdb,0xaa,0xb2,0x25,0xd9,0x92,
0xab,0xca,0xe5,0xd2,0xed,0x02,0xc9,0xa4,0x88,0x32,0x08,0xb0,0x00,0x50,0x8b,0x65,0xde,0x33,0xf3,0x08,


+ 1
- 2
code/espurna/static/index.rfm69.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 28542
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0x6b,0x76,0xdb,0x48,0xd2,0x28,0xf8,0xff,
0x5b,0x05,0x0c,0x77,0xcb,0x64,0x1b,0x7c,0xea,0x69,0xd2,0x92,0x3f,0x5a,0x92,0x6d,0x55,0xd9,0x92,0x6c,
0xc9,0xe5,0x72,0xb9,0xf4,0x75,0x81,0x24,0x48,0xa2,0x0c,0x02,0x2c,0x00,0x94,0x2c,0xcb,0xbc,0x67,0x66,


+ 1
- 2
code/espurna/static/index.sensor.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 30407
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0x6b,0x76,0xdb,0x48,0xd2,0x28,0xf8,0xbf,
0x57,0x01,0xc3,0xdd,0x32,0xd9,0x06,0x9f,0x7a,0x9a,0x34,0xe5,0x8f,0x96,0x64,0x5b,0x55,0xb6,0x24,0x5b,
0x72,0x55,0xb9,0x5c,0xfa,0xca,0x20,0x09,0x8a,0x28,0x83,0x00,0x0b,0x00,0x25,0xcb,0x32,0xef,0x99,0x59,


+ 1
- 2
code/espurna/static/index.small.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 27497
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0xe9,0x76,0xdb,0x48,0xb2,0x30,0xf8,0xbf,
0x9f,0x02,0x86,0xbb,0x6d,0xb2,0x0d,0xae,0x5a,0x4d,0x5a,0xf2,0xa5,0x16,0xdb,0xaa,0xb2,0x25,0xd9,0x92,
0xab,0xca,0xe5,0xd2,0xed,0x02,0x49,0x50,0x44,0x19,0x04,0x58,0x00,0xa8,0xc5,0x32,0xef,0x99,0x79,0x84,


+ 1
- 2
code/espurna/static/index.thermostat.html.gz.h View File

@ -1,5 +1,4 @@
#define webui_image_len 28209
const uint8_t webui_image[] PROGMEM = {
alignas(4) static constexpr uint8_t webui_image[] PROGMEM = {
0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0xec,0xbd,0x69,0x76,0x1b,0xc7,0xb2,0x30,0xf8,0xff,
0xae,0xa2,0x54,0xf2,0x95,0x80,0xab,0xc2,0xc8,0x19,0x10,0xa9,0x07,0x0e,0x12,0x69,0x4b,0x24,0x25,0x52,
0xb6,0x65,0x99,0xcf,0x2e,0x00,0x09,0xa2,0x4c,0xa0,0x0a,0xae,0x2a,0x70,0x10,0x85,0x77,0xba,0x97,0xd0,


+ 11
- 8
code/espurna/web.cpp View File

@ -213,17 +213,20 @@ size_t AsyncWebPrint::write(const uint8_t* data, size_t size) {
namespace {
static constexpr char _last_modified[] PROGMEM = __DATE__ " " __TIME__ "GMT";
alignas(4) static constexpr char LastModified[] PROGMEM = __DATE__ " " __TIME__ " GMT";
static constexpr size_t WebConfigBufferMax { 4096 };
// server instance can't (yet) be static, port is the ctor argument :/
AsyncWebServer* _server;
std::vector<uint8_t> * _webConfigBuffer;
// XXX shared between requests!
std::vector<uint8_t>* _webConfigBuffer;
bool _webConfigSuccess = false;
// TODO server may not cache the full body
std::vector<web_request_callback_f> _web_request_callbacks;
std::vector<web_body_callback_f> _web_body_callbacks;
static constexpr size_t WebConfigBufferMax { 4096 };
} // namespace
// -----------------------------------------------------------------------------
@ -450,7 +453,7 @@ void _onHome(AsyncWebServerRequest *request) {
if (request->hasHeader(FPSTR(IfModifiedSince))) {
const auto value = request->header(FPSTR(IfModifiedSince));
if (strncmp_P(value.c_str(), _last_modified, value.length()) == 0) {
if (strncmp_P(value.c_str(), LastModified, value.length()) == 0) {
request->send(304);
return;
}
@ -462,7 +465,7 @@ void _onHome(AsyncWebServerRequest *request) {
const size_t max = (systemFreeHeap() / 3) & 0xFFE0;
auto* response = request->beginChunkedResponse("text/html", [max](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
// Get the chunk based on the index and maxLen
size_t len = webui_image_len - index;
size_t len = std::size(webui_image) - index;
len = std::min({len, maxLen, max});
if (len > 0) {
memcpy_P(buffer, webui_image + index, len);
@ -472,11 +475,11 @@ void _onHome(AsyncWebServerRequest *request) {
return len;
});
#else
auto* response = request->beginResponse_P(200, F("text/html"), webui_image, webui_image_len);
auto* response = request->beginResponse_P(200, F("text/html"), webui_image, std::size(webui_image));
#endif
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader(F("Last-Modified"), _last_modified);
response->addHeader(F("Last-Modified"), FPSTR(LastModified));
response->addHeader(F("X-XSS-Protection"), F("1; mode=block"));
response->addHeader(F("X-Content-Type-Options"), F("nosniff"));
response->addHeader(F("X-Frame-Options"), F("deny"));


+ 1
- 2
code/gulpfile.js View File

@ -75,8 +75,7 @@ var toHeader = function(name, debug) {
// Generate output
var output = '';
output += '#define ' + safename + '_len ' + source.contents.length + '\n';
output += 'const uint8_t ' + safename + '[] PROGMEM = {';
output += 'alignas(4) static constexpr uint8_t ' + safename + '[] PROGMEM = {';
for (var i=0; i<source.contents.length; i++) {
if (i > 0) { output += ','; }
if (0 === (i % 20)) { output += '\n'; }


Loading…
Cancel
Save