Skip to content

Commit

Permalink
🐛 fix: respect Immutable config for Body()
Browse files Browse the repository at this point in the history
  • Loading branch information
nickajacks1 committed Dec 12, 2024
1 parent 8c84b0f commit 6b13a95
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -354,6 +354,9 @@ func (c *Ctx) Body() []byte {
return []byte(err.Error())
}

if c.app.config.Immutable {
return utils.CopyBytes(body)
}
return body
}

Expand Down Expand Up @@ -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()
}

0 comments on commit 6b13a95

Please sign in to comment.