Skip to content

Commit

Permalink
Improved raw content
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Sep 20, 2024
1 parent 4acd6e0 commit 1f3c071
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/server/injectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function normalizeRequest(targets: Array<string>, 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();
Expand All @@ -99,8 +100,18 @@ function normalizeRequest(targets: Array<string>, 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) {
Expand All @@ -121,7 +132,7 @@ function normalizeRequest(targets: Array<string>, req: Request): KrasRequest {
method,
headers,
content,
rawContent: req.body,
rawContent,
formData,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/types/kras-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 1f3c071

Please sign in to comment.