mirror of https://github.com/gofiber/fiber.git
🐛 fix: Respect Immutable config for Body() (#3246)
* 🐛 fix: respect Immutable config for Body()
* ci: add go 1.22 and 1.23 to test matrix
pull/3259/head
parent
8c84b0fd8a
commit
56ff2de858
|
@ -17,7 +17,7 @@ jobs:
|
|||
Build:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x]
|
||||
go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x]
|
||||
platform: [ubuntu-latest, windows-latest, macos-latest]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
|
|
15
ctx.go
15
ctx.go
|
@ -268,7 +268,7 @@ func (c *Ctx) BaseURL() string {
|
|||
// Returned value is only valid within the handler. Do not store any references.
|
||||
// Make copies or use the Immutable setting instead.
|
||||
func (c *Ctx) BodyRaw() []byte {
|
||||
return c.fasthttp.Request.Body()
|
||||
return c.getBody()
|
||||
}
|
||||
|
||||
func (c *Ctx) tryDecodeBodyInOrder(
|
||||
|
@ -340,7 +340,7 @@ func (c *Ctx) Body() []byte {
|
|||
// rule defined at: https://www.rfc-editor.org/rfc/rfc9110#section-8.4-5
|
||||
encodingOrder = getSplicedStrList(headerEncoding, encodingOrder)
|
||||
if len(encodingOrder) == 0 {
|
||||
return c.fasthttp.Request.Body()
|
||||
return c.getBody()
|
||||
}
|
||||
|
||||
var decodesRealized uint8
|
||||
|
@ -354,6 +354,9 @@ func (c *Ctx) Body() []byte {
|
|||
return []byte(err.Error())
|
||||
}
|
||||
|
||||
if c.app.config.Immutable {
|
||||
return utils.CopyBytes(body)
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
|
@ -2004,3 +2007,11 @@ func (*Ctx) isLocalHost(address string) bool {
|
|||
func (c *Ctx) IsFromLocal() bool {
|
||||
return c.isLocalHost(c.fasthttp.RemoteIP().String())
|
||||
}
|
||||
|
||||
func (c *Ctx) getBody() []byte {
|
||||
if c.app.config.Immutable {
|
||||
return utils.CopyBytes(c.fasthttp.Request.Body())
|
||||
}
|
||||
|
||||
return c.fasthttp.Request.Body()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue