@@ -273,10 +273,7 @@ func (c *DefaultCtx) BaseURL() string {
273
273
// Returned value is only valid within the handler. Do not store any references.
274
274
// Make copies or use the Immutable setting instead.
275
275
func (c * DefaultCtx ) BodyRaw () []byte {
276
- if c .app .config .Immutable {
277
- return utils .CopyBytes (c .fasthttp .Request .Body ())
278
- }
279
- return c .fasthttp .Request .Body ()
276
+ return c .getBody ()
280
277
}
281
278
282
279
func (c * DefaultCtx ) tryDecodeBodyInOrder (
@@ -344,20 +341,14 @@ func (c *DefaultCtx) Body() []byte {
344
341
345
342
// If no encoding is provided, return the original body
346
343
if len (headerEncoding ) == 0 {
347
- if c .app .config .Immutable {
348
- return utils .CopyBytes (c .fasthttp .Request .Body ())
349
- }
350
- return c .fasthttp .Request .Body ()
344
+ return c .getBody ()
351
345
}
352
346
353
347
// Split and get the encodings list, in order to attend the
354
348
// rule defined at: https://www.rfc-editor.org/rfc/rfc9110#section-8.4-5
355
349
encodingOrder = getSplicedStrList (headerEncoding , encodingOrder )
356
350
if len (encodingOrder ) == 0 {
357
- if c .app .config .Immutable {
358
- return utils .CopyBytes (c .fasthttp .Request .Body ())
359
- }
360
- return c .fasthttp .Request .Body ()
351
+ return c .getBody ()
361
352
}
362
353
363
354
var decodesRealized uint8
@@ -1913,6 +1904,14 @@ func (c *DefaultCtx) release() {
1913
1904
}
1914
1905
}
1915
1906
1907
+ func (c * DefaultCtx ) getBody () []byte {
1908
+ if c .app .config .Immutable {
1909
+ return utils .CopyBytes (c .fasthttp .Request .Body ())
1910
+ }
1911
+
1912
+ return c .fasthttp .Request .Body ()
1913
+ }
1914
+
1916
1915
// Methods to use with next stack.
1917
1916
func (c * DefaultCtx ) getMethodINT () int {
1918
1917
return c .methodINT
0 commit comments