Skip to content

Commit

Permalink
Added a way to decode only the response (seperated decode instruction…
Browse files Browse the repository at this point in the history
… into request, response)
  • Loading branch information
duart38 committed Aug 17, 2020
1 parent 8b616bc commit c792aa8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion components/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion interfaces/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions models/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export const sandbox = async (): Promise<Model> => {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*'
},
type: HTTP.GET,
decode: true
type: HTTP.POST,
decode: true,
decodeResponse: false
},
},
SOCKET: {
Expand Down

0 comments on commit c792aa8

Please sign in to comment.