File tree Expand file tree Collapse file tree
packages/server/src/middleware Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,27 +78,34 @@ export function createBodyParser(opts = {}) {
7878
7979 return async function ( ctx ) {
8080 let bodyResult ;
81+ let rawBodyResult ;
8182 // only parse the body on specifically chosen methods
8283 // @ts -ignore
8384 if ( opts . parsedMethods . includes ( ctx . method . toUpperCase ( ) ) ) {
8485 try {
8586 if ( opts . json && ctx . is ( jsonTypes ) ) {
86- bodyResult = await coBody . json ( ctx , {
87+ const result = await coBody . json ( ctx , {
8788 encoding : opts . encoding ,
8889 limit : opts . jsonLimit ,
8990 strict : true ,
90- returnRawBody : false ,
91+ returnRawBody : true ,
9192 } ) ;
93+
94+ bodyResult = result . parsed ;
95+ rawBodyResult = result . raw ;
9296 } else if (
9397 opts . urlencoded &&
9498 ctx . is ( "application/x-www-form-urlencoded" )
9599 ) {
96- bodyResult = await coBody . form ( ctx , {
100+ const result = await coBody . form ( ctx , {
97101 encoding : opts . encoding ,
98102 limit : opts . urlencodedLimit ,
99103 queryString : opts . queryString ,
100- returnRawBody : false ,
104+ returnRawBody : true ,
101105 } ) ;
106+
107+ bodyResult = result . parsed ;
108+ rawBodyResult = result . raw ;
102109 } else if ( opts . text && ctx . is ( "text/*" ) ) {
103110 bodyResult = await coBody . text ( ctx , {
104111 encoding : opts . encoding ,
@@ -158,5 +165,7 @@ export function createBodyParser(opts = {}) {
158165
159166 // @ts -expect-error
160167 ctx . request . body = bodyResult ;
168+ // @ts -expect-error
169+ ctx . request . rawBody = rawBodyResult ;
161170 } ;
162171}
You can’t perform that action at this time.
0 commit comments