-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9926 from tolgap/fix/9901-urlencoded-raw-body
fix(express,fastify): raw body for urlencoded requests
- Loading branch information
Showing
5 changed files
with
183 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/platform-express/adapters/utils/get-body-parser-options.util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { RawBodyRequest } from '@nestjs/common'; | ||
import type { Options } from 'body-parser'; | ||
import type { IncomingMessage, ServerResponse } from 'http'; | ||
|
||
const rawBodyParser = ( | ||
req: RawBodyRequest<IncomingMessage>, | ||
_res: ServerResponse, | ||
buffer: Buffer, | ||
) => { | ||
if (Buffer.isBuffer(buffer)) { | ||
req.rawBody = buffer; | ||
} | ||
return true; | ||
}; | ||
|
||
export function getBodyParserOptions<ParserOptions extends Options>( | ||
rawBody: boolean, | ||
options?: ParserOptions | undefined, | ||
): ParserOptions { | ||
let parserOptions: ParserOptions = options ?? ({} as ParserOptions); | ||
|
||
if (rawBody === true) { | ||
parserOptions = { | ||
...parserOptions, | ||
verify: rawBodyParser, | ||
}; | ||
} | ||
|
||
return parserOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters