diff --git a/source/Main/externalpluginservers.rs b/source/Main/externalpluginservers.rs index a461321..7577f36 100644 --- a/source/Main/externalpluginservers.rs +++ b/source/Main/externalpluginservers.rs @@ -96,9 +96,19 @@ struct EPSResponse { #[serde(tag = "as")] pub(crate) enum EPSResponseBody { NoneOk, - OkString { value: String }, - Json { value: String }, - Error { message: Option }, + WebResponse { + append_headers: Vec<(String, String)>, + response_body: String, + }, + OkString { + value: String, + }, + Json { + value: String, + }, + Error { + message: Option, + }, Disabled, } diff --git a/source/Main/requestresponse.rs b/source/Main/requestresponse.rs index a9261e0..35326c5 100644 --- a/source/Main/requestresponse.rs +++ b/source/Main/requestresponse.rs @@ -81,6 +81,16 @@ pub(crate) async fn serve( ) .await; match pluginsresponse { + crate::externalpluginservers::EPSResponseBody::WebResponse { + append_headers, + response_body, + } => { + let mut response = HttpResponse::build(actix_web::http::StatusCode::OK); + for (k, v) in append_headers { + response.append_header((k, v)); + } + return response.body(response_body); + } crate::externalpluginservers::EPSResponseBody::NoneOk => {} crate::externalpluginservers::EPSResponseBody::Disabled => {} _ => return HttpResponse::InternalServerError().body("Internal server error."), diff --git a/source/Plugin-runners/node-plugin-api/main.ts b/source/Plugin-runners/node-plugin-api/main.ts index cbdae0a..9a5fc52 100644 --- a/source/Plugin-runners/node-plugin-api/main.ts +++ b/source/Plugin-runners/node-plugin-api/main.ts @@ -161,7 +161,7 @@ export interface WebResponse { id: number; body: { as: "WebResponse"; - append_headers: Record; + append_headers: Array<[string, string]>; response_body: string; }; } @@ -222,7 +222,7 @@ export const Cynthia = { console: terminalOut, }; export interface ResponderResponse { - headers: Record; + headers: Array<[string, string]>; body: string; } export type Responder = () => ResponderResponse; @@ -249,18 +249,18 @@ export interface IncomingWebRequest { for: "WebRequest"; method: string; uri: string; - headers: Record; + headers: Array<[string, string]>; }; } export class WebRequest { private id: number; private method: string; uri: string; - headers: Record; + headers: Array<[string, string]>; private respondand: boolean; constructor( id: number, - a: { method: string; uri: string; headers: Record }, + a: { method: string; uri: string; headers: Array<[string, string]> }, ) { this.id = id; this.method = a.method; @@ -284,7 +284,6 @@ export class WebRequest { Cynthia.send(response); } private matchUris(str: string, rule: string) { - Cynthia.console.info(`matchUris: '${str}'; '${rule}'`); if (str === rule) return true; // biome-ignore lint/style/noVar: This is a regex, not a variable @@ -316,4 +315,12 @@ export class WebRequest { this.respond(responder); } } + escalate() { + if (this.stillResponding()) { + this.respondand = true; + const response = new EmptyOKResponse(this.id); + return Cynthia.send(response); + } + return; + } } diff --git a/source/Plugin-runners/node-plugin-runner/src/handler.ts b/source/Plugin-runners/node-plugin-runner/src/handler.ts index 3e9e95a..588662b 100644 --- a/source/Plugin-runners/node-plugin-runner/src/handler.ts +++ b/source/Plugin-runners/node-plugin-runner/src/handler.ts @@ -45,9 +45,7 @@ export default async function handle(buffer: Buffer, cynthiabase: PluginBase) { modifier(req, CynthiaPassed); } - // Until this is implemented, we will just return EmptyOk. - const response = new EmptyOKResponse(request.id); - return Cynthia.send(response); + return req.escalate(); } case "PostlistRenderRequest": { try { diff --git a/source/Plugin-runners/node-plugin-runner/src/types/internal_plugins.ts b/source/Plugin-runners/node-plugin-runner/src/types/internal_plugins.ts index 1aedc4d..15001af 100644 --- a/source/Plugin-runners/node-plugin-runner/src/types/internal_plugins.ts +++ b/source/Plugin-runners/node-plugin-runner/src/types/internal_plugins.ts @@ -45,9 +45,8 @@ export const newPluginBase: PluginBase = { }, (req: WebRequest, Cynthia: typeof CynthiaPassed) => { req.get("/pltest*", () => { - Cynthia.console.info("Request for /pltest received!"); const a: ResponderResponse = { - headers: {}, + headers: [], body: "This is a test response.", }; return a;