diff --git a/src/server/injectors/index.ts b/src/server/injectors/index.ts index b9ce1b8..c41c344 100644 --- a/src/server/injectors/index.ts +++ b/src/server/injectors/index.ts @@ -83,6 +83,7 @@ function normalizeRequest(targets: Array, req: Request): KrasRequest { let content: string | FormData; let formData: FormData; + let rawContent: Buffer; if (req.headers['content-type'] && req.headers['content-type'].search('multipart/form-data') !== -1) { formData = new FormData(); @@ -99,8 +100,18 @@ function normalizeRequest(targets: Array, req: Request): KrasRequest { }); headers['content-type'] = formData.getHeaders()['content-type']; content = formData; + rawContent = formData.getBuffer(); + } else if (typeof req.body === 'string') { + content = req.body; + rawContent = Buffer.from(content); } else { - content = typeof req.body === 'string' ? req.body : ''; + content = ''; + + try { + rawContent = Buffer.from(req.body); + } catch { + rawContent = Buffer.from(''); + } } for (const name of req.removedHeaders) { @@ -121,7 +132,7 @@ function normalizeRequest(targets: Array, req: Request): KrasRequest { method, headers, content, - rawContent: req.body, + rawContent, formData, }; } diff --git a/src/server/types/kras-request.ts b/src/server/types/kras-request.ts index 8928faa..cbe0dc0 100644 --- a/src/server/types/kras-request.ts +++ b/src/server/types/kras-request.ts @@ -33,7 +33,7 @@ export interface BasicKrasRequest { /** * The raw content of the request. */ - rawContent: any; + rawContent: Buffer; /** * The form data, in case a form was given. */