From 6b13a952cd3a9a15791349c6b7d6ec2c40d16d9e Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Wed, 11 Dec 2024 16:18:56 -0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20respect=20Immutable?= =?UTF-8?q?=20config=20for=20Body()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ctx.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ctx.go b/ctx.go index 6f414ed56a..c7caada702 100644 --- a/ctx.go +++ b/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() +} From 06ad8890dd79c026b266ec0e3cb375e621f740a7 Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Thu, 12 Dec 2024 10:47:46 -0800 Subject: [PATCH 2/2] ci: add go 1.22 and 1.23 to test matrix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a186908aa0..00566dd9c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: