Skip to content

Commit

Permalink
Merge branch 'main' into pr/3016
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Sep 19, 2024
2 parents b262a08 + fbc24e8 commit 937a9b3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/client/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down Expand Up @@ -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.

Expand Down
7 changes: 6 additions & 1 deletion middleware/adaptor/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions middleware/adaptor/adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions middleware/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -75,7 +75,7 @@ func New(config ...Config) fiber.Handler {
// Update timestamp in the configured interval
go func() {
for {
atomic.StoreUint64(&timestamp, uint64(time.Now().Unix()))
atomic.StoreUint64(&timestamp, uint64(time.Now().Unix())) //nolint:gosec //Not a concern
time.Sleep(timestampUpdatePeriod)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion middleware/etag/etag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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('"')
Expand Down

0 comments on commit 937a9b3

Please sign in to comment.