From 311dc3fb9286dfc16985a1031de2cfa619ff8c29 Mon Sep 17 00:00:00 2001 From: yinheli Date: Sat, 14 Sep 2024 23:36:19 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=9A=20Doc:=20Fix=20typos=20in=20cl?= =?UTF-8?q?ient=20hooks=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/client/hooks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/client/hooks.md b/docs/client/hooks.md index 8616eac792..ccbc7d408e 100644 --- a/docs/client/hooks.md +++ b/docs/client/hooks.md @@ -2,7 +2,7 @@ id: hooks title: 🎣 Hooks description: >- - Hooks are used to manipulate request/response proccess of Fiber client. + Hooks are used to manipulate request/response process of Fiber client. sidebar_position: 4 --- @@ -77,7 +77,7 @@ There are also some builtin request hooks provide some functionalities for Fiber - [parserRequestURL](https://github.com/gofiber/fiber/blob/main/client/hooks.go#L62): parserRequestURL customizes the URL according to the path params and query params. It's necessary for `PathParam` and `QueryParam` methods. -- [parserRequestHeader](https://github.com/gofiber/fiber/blob/main/client/hooks.go#L113): parserRequestHeader sets request headers, cookies, body type, referer, user agent according to client and request proeprties. It's necessary to make request header and cookiejar methods functional. +- [parserRequestHeader](https://github.com/gofiber/fiber/blob/main/client/hooks.go#L113): parserRequestHeader sets request headers, cookies, body type, referer, user agent according to client and request properties. It's necessary to make request header and cookiejar methods functional. - [parserRequestBody](https://github.com/gofiber/fiber/blob/main/client/hooks.go#L178): parserRequestBody serializes the body automatically. It is useful for XML, JSON, form, file bodies. From 37f1a65c4cae47b607f50bee99c98a4dcf04ec52 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:05:16 +0200 Subject: [PATCH 2/4] build(deps): bump DavidAnson/markdownlint-cli2-action from 16 to 17 (#3128) Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) from 16 to 17. - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/v16...v17) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> --- .github/workflows/markdown.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/markdown.yml b/.github/workflows/markdown.yml index cc131e7fb2..d8d74905e4 100644 --- a/.github/workflows/markdown.yml +++ b/.github/workflows/markdown.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Run markdownlint-cli2 - uses: DavidAnson/markdownlint-cli2-action@v16 + uses: DavidAnson/markdownlint-cli2-action@v17 with: globs: | **/*.md From 0ef8d716eef802143cfc3cbaefa9fd71b4a03589 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:28:22 -0400 Subject: [PATCH 3/4] Bump golangci-lint to v1.61.0 (#3135) * Bump golangci-lint to v1.61.0 * Fix golangci warnings --- .github/workflows/linter.yml | 2 +- Makefile | 2 +- middleware/cache/cache.go | 4 ++-- middleware/etag/etag.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6c378e4043..dc04fec67b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -37,4 +37,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: # NOTE: Keep this in sync with the version from .golangci.yml - version: v1.60.3 + version: v1.61.0 diff --git a/Makefile b/Makefile index 1d7f57d03c..33526991a3 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ markdown: ## lint: 🚨 Run lint checks .PHONY: lint lint: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 run ./... + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 run ./... ## test: 🚦 Execute all tests .PHONY: test diff --git a/middleware/cache/cache.go b/middleware/cache/cache.go index 69c3fd5c1d..f593b56e4e 100644 --- a/middleware/cache/cache.go +++ b/middleware/cache/cache.go @@ -63,7 +63,7 @@ func New(config ...Config) fiber.Handler { var ( // Cache settings mux = &sync.RWMutex{} - timestamp = uint64(time.Now().Unix()) + timestamp = uint64(time.Now().Unix()) //nolint:gosec //Not a concern ) // Create manager to simplify storage operations ( see manager.go ) manager := newManager(cfg.Storage) @@ -75,7 +75,7 @@ func New(config ...Config) fiber.Handler { // Update timestamp in the configured interval go func() { for { - atomic.StoreUint64(×tamp, uint64(time.Now().Unix())) + atomic.StoreUint64(×tamp, uint64(time.Now().Unix())) //nolint:gosec //Not a concern time.Sleep(timestampUpdatePeriod) } }() diff --git a/middleware/etag/etag.go b/middleware/etag/etag.go index aca57bc1e7..f28a33cec5 100644 --- a/middleware/etag/etag.go +++ b/middleware/etag/etag.go @@ -65,7 +65,7 @@ func New(config ...Config) fiber.Handler { return c.SendStatus(fiber.StatusRequestEntityTooLarge) } - bb.B = appendUint(bb.Bytes(), uint32(bodyLength)) //nolint:gosec // Body length is validated above + bb.B = appendUint(bb.Bytes(), uint32(bodyLength)) bb.WriteByte('-') bb.B = appendUint(bb.Bytes(), crc32.Checksum(body, crc32q)) bb.WriteByte('"') From fbc24e83d63653237decfe86a6684bc5a417ff28 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:45:44 -0400 Subject: [PATCH 4/4] v3: Fix issue with default logger when creating RequestCtx (#3134) Use Noop Logger when creating RequestCtx --- middleware/adaptor/adaptor.go | 7 ++++++- middleware/adaptor/adaptor_test.go | 29 ++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/middleware/adaptor/adaptor.go b/middleware/adaptor/adaptor.go index 539aa3e24b..a5040b39ae 100644 --- a/middleware/adaptor/adaptor.go +++ b/middleware/adaptor/adaptor.go @@ -14,6 +14,11 @@ import ( "github.com/valyala/fasthttp/fasthttpadaptor" ) +type disableLogger struct{} + +func (*disableLogger) Printf(string, ...any) { +} + var ctxPool = sync.Pool{ New: func() any { return new(fasthttp.RequestCtx) @@ -171,7 +176,7 @@ func handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc { fctx.Response.Reset() fctx.Request.Reset() defer ctxPool.Put(fctx) - fctx.Init(req, remoteAddr, nil) + fctx.Init(req, remoteAddr, &disableLogger{}) if len(h) > 0 { // New fiber Ctx diff --git a/middleware/adaptor/adaptor_test.go b/middleware/adaptor/adaptor_test.go index 32abc64d93..c703d38436 100644 --- a/middleware/adaptor/adaptor_test.go +++ b/middleware/adaptor/adaptor_test.go @@ -86,7 +86,7 @@ func Test_HTTPHandler(t *testing.T) { remoteAddr, err := net.ResolveTCPAddr("tcp", expectedRemoteAddr) require.NoError(t, err) - fctx.Init(&req, remoteAddr, nil) + fctx.Init(&req, remoteAddr, &disableLogger{}) app := fiber.New() ctx := app.AcquireCtx(&fctx) defer app.ReleaseCtx(ctx) @@ -412,6 +412,10 @@ func Benchmark_FiberHandlerFunc(b *testing.B) { name string bodyContent []byte }{ + { + name: "No Content", + bodyContent: nil, // No body content case + }, { name: "100KB", bodyContent: make([]byte, 100*1024), @@ -450,7 +454,14 @@ func Benchmark_FiberHandlerFunc(b *testing.B) { for _, bm := range benchmarks { b.Run(bm.name, func(b *testing.B) { w := httptest.NewRecorder() - bodyBuffer := bytes.NewBuffer(bm.bodyContent) + var bodyBuffer *bytes.Buffer + + // Handle the "No Content" case where bodyContent is nil + if bm.bodyContent != nil { + bodyBuffer = bytes.NewBuffer(bm.bodyContent) + } else { + bodyBuffer = bytes.NewBuffer([]byte{}) // Empty buffer for no content + } r := http.Request{ Method: http.MethodPost, @@ -476,6 +487,10 @@ func Benchmark_FiberHandlerFunc_Parallel(b *testing.B) { name string bodyContent []byte }{ + { + name: "No Content", + bodyContent: nil, // No body content case + }, { name: "100KB", bodyContent: make([]byte, 100*1024), @@ -513,7 +528,15 @@ func Benchmark_FiberHandlerFunc_Parallel(b *testing.B) { for _, bm := range benchmarks { b.Run(bm.name, func(b *testing.B) { - bodyBuffer := bytes.NewBuffer(bm.bodyContent) + var bodyBuffer *bytes.Buffer + + // Handle the "No Content" case where bodyContent is nil + if bm.bodyContent != nil { + bodyBuffer = bytes.NewBuffer(bm.bodyContent) + } else { + bodyBuffer = bytes.NewBuffer([]byte{}) // Empty buffer for no content + } + b.ReportAllocs() b.ResetTimer()