PsychicHttp V2 #27
Replies: 7 comments 15 replies
-
Of cource we will investigate the v2 version of psychic and try to implement it, or make useable both version with a directive. Thank you for your info. |
Beta Was this translation helpful? Give feedback.
-
In my test sketch it was enough to replace all occourences of PsychicHttpRequest *request with PsychicHttpRequest *request, PsychicHttpResponse *response for now but as soon as I compile my react app it falls apart and I have to replace it again. :D |
Beta Was this translation helpful? Give feedback.
-
I think something like this would be enough: commandLine.ts interface ICopyFilesArguments {
engine: 'psychic' | 'async';
psychicv2: boolean; // <-- Added psychicv2
sourcepath: string;
outputfile: string;
espmethod: string;
define: string;
gzip: 'true' | 'false' | 'compiler';
etag: 'true' | 'false' | 'compiler';
created: boolean;
version: string;
help?: boolean;
}
export const cmdLine = parse<ICopyFilesArguments>(
{
engine: {
type: (value) => {
if (value === 'psychic') return 'psychic';
if (value === 'async') return 'async';
throw new Error(`Invalid engine: ${value}`);
},
alias: 'e',
description: 'The engine for which the include file is created (psychic|async)',
defaultValue: 'psychic'
},
psychicv2: { // <--- Added psychicv2
type: Boolean,
alias: 'psychivV2',
description: 'Use v2 of the psychic engine',
defaultValue: false
},
sourcepath: {
type: String,
alias: 's',
description: 'Source dist folder contains compiled web files'
},
outputfile: {
type: String,
alias: 'o',
description: 'Generated output file with path',
defaultValue: 'svelteesp32.h'
},
etag: {
type: (value) => {
if (value === 'true') return 'true';
if (value === 'false') return 'false';
if (value === 'compiler') return 'compiler';
throw new Error(`Invalid etag: ${value}`);
},
description: 'Use ETAG header for cache',
defaultValue: 'false'
},
gzip: {
type: (value) => {
if (value === 'true') return 'true';
if (value === 'false') return 'false';
if (value === 'compiler') return 'compiler';
throw new Error(`Invalid etag: ${value}`);
},
description: 'Compress content with gzip',
defaultValue: 'true'
},
created: {
type: Boolean,
description: 'Include creation time in the output file',
defaultValue: false
},
version: {
type: String,
description: 'Include version info in the output file',
defaultValue: ''
},
espmethod: {
type: String,
description: 'Name of generated method',
defaultValue: 'initSvelteStaticFiles'
},
define: {
type: String,
description: 'Prefix of c++ defines',
defaultValue: 'SVELTEESP32'
},
help: { type: Boolean, optional: true, alias: 'h', description: 'Shows this help' }
},
{
helpArg: 'help',
headerContentSections: [{ header: 'svelteesp32', content: 'Svelte JS to ESP32 converter' }]
}
); cppCode.ts //
// Http Handlers
void {{methodName}}(PsychicHttpServer * server) {
{{#each sources}}
//
// {{this.filename}}
{{#if this.isDefault}}server->defaultEndpoint = {{/if}}server->on("/{{this.filename}}", HTTP_GET, [](PsychicRequest * request {{#if this.psychicv2}} , PsychicResponse *resp {{/if}}) {
{{#switch ../etag}}
{{#case "true"}}
if (request->hasHeader("If-None-Match") && request->header("If-None-Match") == String(etag_{{this.dataname}})) {
PsychicResponse response304(request);
response304.setCode(304);
return response304.send();
}
{{/case}}
{{#case "compiler"}}
#ifdef {{../definePrefix}}_ENABLE_ETAG
if (request->hasHeader("If-None-Match") && request->header("If-None-Match") == String(etag_{{this.dataname}})) {
PsychicResponse response304(request);
response304.setCode(304);
return response304.send();
}
#endif
{{/case}}
{{/switch}}
PsychicResponse response(request);
response.setContentType("{{this.mime}}");
{{#switch ../gzip}}
{{#case "true"}}
{{#if this.isGzip}}
response.addHeader("Content-Encoding", "gzip");
{{/if}}
{{/case}}
{{#case "compiler"}}
{{#if this.isGzip}}
#ifdef {{../definePrefix}}_ENABLE_GZIP
response.addHeader("Content-Encoding", "gzip");
#endif
{{/if}}
{{/case}}
{{/switch}}
{{#switch ../etag}}
{{#case "true"}}
response.addHeader("cache-control", "no-cache");
response.addHeader("ETag", etag_{{this.dataname}});
{{/case}}
{{#case "compiler"}}
#ifdef {{../definePrefix}}_ENABLE_ETAG
response.addHeader("cache-control", "no-cache");
response.addHeader("ETag", etag_{{this.dataname}});
#endif
{{/case}}
{{/switch}}
{{#switch ../gzip}}
{{#case "true"}}
response.setContent(datagzip_{{this.dataname}}, {{this.lengthGzip}});
{{/case}}
{{#case "false"}}
response.setContent(data_{{this.dataname}}, {{this.length}});
{{/case}}
{{#case "compiler"}}
#ifdef {{../definePrefix}}_ENABLE_GZIP
response.setContent(datagzip_{{this.dataname}}, {{this.lengthGzip}});
#else
response.setContent(data_{{this.dataname}}, {{this.length}});
#endif
{{/case}}
{{/switch}}
return response.send();
}); Actually It just adds an other parameter to the handler |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm thinking because I need to develop with v2. I want to test it and things like that but I must keep rewriting the header over and over again. |
Beta Was this translation helpful? Give feedback.
-
If we believe that v2 is sufficiently stable, we can slowly implement the utility. I will gladly make the code. |
Beta Was this translation helpful? Give feedback.
-
Remark: in Psychic V2 listen() changed to begin() |
Beta Was this translation helpful? Give feedback.
-
Released in v1.5, use I would like a feedback about it! And close discussion if it is completed. |
Beta Was this translation helpful? Give feedback.
-
Hello! The author and a couple of guys started to develop PsychicHttp Version 2. It includes breaking changes. Endpoint callbacks now getting two parameters instead of one, request and response and things like that. Do you have any plan to include a v2 directive?
Beta Was this translation helpful? Give feedback.
All reactions