From c792aa850817466451a8c7b56a94706545ea8993 Mon Sep 17 00:00:00 2001 From: duart38 Date: Mon, 17 Aug 2020 16:48:33 +0200 Subject: [PATCH] Added a way to decode only the response (seperated decode instruction into request, response) --- components/httpServer.ts | 5 ++++- interfaces/model.ts | 6 +++++- models/sandbox.ts | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/httpServer.ts b/components/httpServer.ts index 11fbd08..0b324da 100644 --- a/components/httpServer.ts +++ b/components/httpServer.ts @@ -121,7 +121,10 @@ export default class httpServer { ); } - const body = config.decode ? JSON.stringify(await relayValue.json()) : await relayValue.text(); + /** + * Decoded body or text.. + */ + const body = config.decodeResponse ? JSON.stringify(await relayValue.json()) : await relayValue.text(); req.respond({ body: body || undefined, headers: constructHeaders(req, config), diff --git a/interfaces/model.ts b/interfaces/model.ts index a321bbc..19051b4 100644 --- a/interfaces/model.ts +++ b/interfaces/model.ts @@ -16,9 +16,13 @@ export interface HTTPModelMethod { headers: HeaderEntries type: HTTP; /** - * Indicates wether we want to decode the body (from int8arr) before we forward + * Indicates wether we want to decode the body (from int8arr) before we forward to the relay server */ decode?: boolean; + /** + * Indicates wether we want to decode the body to JSON before we send it back to the CLIENT + */ + decodeResponse?: boolean /** * Used to specifiy what headers are required to continue with the request.. the middleware will discard the request in case a header is missing. * An error is returned when there is a missing header diff --git a/models/sandbox.ts b/models/sandbox.ts index ac71a4f..5a15a47 100644 --- a/models/sandbox.ts +++ b/models/sandbox.ts @@ -19,8 +19,9 @@ export const sandbox = async (): Promise => { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*' }, - type: HTTP.GET, - decode: true + type: HTTP.POST, + decode: true, + decodeResponse: false }, }, SOCKET: {