Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update cppCode.ts
Add some pointers to the default document, so it can be referred to elsewhere by name ("dataDefaultDocument", "lengthDefaultDocument", "etagDefaultDocument"). That way, I can do this to keep SvelteKit routing happy: server.onNotFound([](AsyncWebServerRequest *request) { if (request->hasHeader("If-None-Match") && request->getHeader("If-None-Match")->value() == String(etagDefaultDocument)) { request->send(304); return; } AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", dataDefaultDocument, lengthDefaultDocument); response->addHeader("Content-Encoding", "gzip"); response->addHeader("ETag", etagDefaultDocument); request->send(response); }); You could also rewrite the template that generates the C++ to just give the default document variables a different name rather than adding pointers, but I figured this was just quick and dirty and achieves the same goal.
  • Loading branch information
kaigoh authored Jul 25, 2024
commit 4b3078c742c28062afa7ba7840445c1c5e0e920e
14 changes: 14 additions & 0 deletions src/cppCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const uint8_t data{{this.index}}[{{this.length}}] = { {{this.bytes}} };
{{#if ../isEtag}}
const char * etag{{this.index}} = "{{this.md5}}";
{{/if}}
{{#if this.isDefault}}
const uint8_t *defaultDocument = &data{{this.index}}[{{this.length}}];
const uint lengthDefaultDocument = {{this.length}};
{{#if ../isEtag}}
const char * etagDefaultDocument = &etag{{this.index}};
{{/if}}
{{/if}}
{{/each}}

void {{methodName}}(PsychicHttpServer * server) {
Expand Down Expand Up @@ -70,6 +77,13 @@ const uint8_t data{{this.index}}[{{this.length}}] PROGMEM = { {{this.bytes}} };
{{#if ../isEtag}}
const char * etag{{this.index}} = "{{this.md5}}";
{{/if}}
{{#if this.isDefault}}
const uint8_t *defaultDocument = &data{{this.index}}[{{this.length}}];
const uint lengthDefaultDocument = {{this.length}};
{{#if ../isEtag}}
const char * etagDefaultDocument = &etag{{this.index}};
{{/if}}
{{/if}}
{{/each}}

void {{methodName}}(AsyncWebServer * server) {
Expand Down