Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3: Consolidate Logic of Handling the Request Body #3093

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@
// Returned value is only valid within the handler. Do not store any references.
// Make copies or use the Immutable setting instead.
func (c *DefaultCtx) BodyRaw() []byte {
if c.app.config.Immutable {
return utils.CopyBytes(c.fasthttp.Request.Body())
}
return c.fasthttp.Request.Body()
return c.getBody()
}

func (c *DefaultCtx) tryDecodeBodyInOrder(
Expand Down Expand Up @@ -344,20 +341,14 @@

// If no encoding is provided, return the original body
if len(headerEncoding) == 0 {
if c.app.config.Immutable {
return utils.CopyBytes(c.fasthttp.Request.Body())
}
return c.fasthttp.Request.Body()
return c.getBody()
}

// Split and get the encodings list, in order to attend the
// rule defined at: https://www.rfc-editor.org/rfc/rfc9110#section-8.4-5
encodingOrder = getSplicedStrList(headerEncoding, encodingOrder)
if len(encodingOrder) == 0 {
if c.app.config.Immutable {
return utils.CopyBytes(c.fasthttp.Request.Body())
}
return c.fasthttp.Request.Body()
return c.getBody()

Check warning on line 351 in ctx.go

View check run for this annotation

Codecov / codecov/patch

ctx.go#L351

Added line #L351 was not covered by tests
}

var decodesRealized uint8
Expand Down Expand Up @@ -1913,6 +1904,14 @@
}
}

func (c *DefaultCtx) getBody() []byte {
if c.app.config.Immutable {
return utils.CopyBytes(c.fasthttp.Request.Body())
}

return c.fasthttp.Request.Body()
}

// Methods to use with next stack.
func (c *DefaultCtx) getMethodINT() int {
return c.methodINT
Expand Down
Loading