Feature implementation from commits c6e0d80..43ad9f7#1
Conversation
* Move binder tests into existing file * Fix lint issues and race condition * Add nolint directive
* test(cors): warn when all origins and func * Fix linter issue
* Refine BasicAuth middleware * Fix lint issues * Update basicauth.md
test(csrf): cover cookie config warnings
* refactor: use utils.ToLower * Improve Cache-Control directive matching * Update middleware/cache/cache.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix lint issue --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* test: validate Is fails for JSON subtype * Update ctx.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update ctx.go * Use immutable-aware getter for Content-Type * Update ctx.go --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: RW <rene@gofiber.io>
…0.0-beta.9 (gofiber#3540) build(deps): bump github.com/gofiber/utils/v2 Bumps [github.com/gofiber/utils/v2](https://github.com/gofiber/utils) from 2.0.0-beta.8 to 2.0.0-beta.9. - [Release notes](https://github.com/gofiber/utils/releases) - [Commits](gofiber/utils@v2.0.0-beta.8...v2.0.0-beta.9) --- updated-dependencies: - dependency-name: github.com/gofiber/utils/v2 dependency-version: 2.0.0-beta.9 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Make custom context setup via NewWithCustomCtx * Update docs/api/app.md * fix lint issues * small optimizations * Fix perf 3476 (gofiber#3499) * perf: modify app.pool goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 36.26n ± 0% 34.51n ± 0% -4.83% (p=0.000 n=30) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal * perf: optimize defaultCtx in app.next ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ new.txt │ new4.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 34.51n ± 0% 30.02n ± 0% -13.01% (p=0.000 n=30) │ new.txt │ new4.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ new.txt │ new4.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` --------- Co-authored-by: Kashiwa <13825170+ksw2000@users.noreply.github.com> * Improve performance gofiber#3476 (gofiber#3532) * Make custom context setup via NewWithCustomCtx * Update docs/api/app.md * fix lint issues * small optimizations * perf: modify app.pool goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 36.26n ± 0% 34.51n ± 0% -4.83% (p=0.000 n=30) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal * perf: optimize defaultCtx in app.next ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ new.txt │ new4.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 34.51n ± 0% 30.02n ± 0% -13.01% (p=0.000 n=30) │ new.txt │ new4.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ new.txt │ new4.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` * perf: revert nextCustom ``` goos: darwin goarch: arm64 pkg: github.com/gofiber/fiber/v3 cpu: Apple M4 │ head.txt │ revert-1.txt │ │ sec/op │ sec/op vs base │ _Communication_Flow-10 30.04n ± 0% 28.74n ± 0% -4.33% (p=0.000 n=30) │ head.txt │ revert-1.txt │ │ B/op │ B/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal │ head.txt │ revert-1.txt │ │ allocs/op │ allocs/op vs base │ _Communication_Flow-10 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=30) ¹ ¹ all samples are equal ``` --------- Co-authored-by: RW <rene@gofiber.io> --------- Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Co-authored-by: Kashiwa <13825170+ksw2000@users.noreply.github.com>
docs: add custom constraint example
* Use utils.ToLower in Subdomains * test: cover Unicode fallback path * fix subdomain extraction for rfc compliance * Address review comments on Subdomains * Address review comments
♻️ refact: use GetState to reduce duplicate code
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.40.0 to 0.41.0. - [Commits](golang/net@v0.40.0...v0.41.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-version: 0.41.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
…lang.org/x/net-0.41.0 build(deps): bump golang.org/x/net from 0.40.0 to 0.41.0
* validate cookies with net/http * refactor: sanitize cookie via net/http * Address review comments * refactor: set cookie attrs via setters * Update ctx.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update ctx.go * Update ctx.go * Update ctx.go * Add more unit-tests * Fix test * Add default case for samesite --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
refactor(ctx): use utils helpers for Range
| } else { | ||
| _, err = c.app.next(c) | ||
| } | ||
| _, err = c.app.next(c) |
There was a problem hiding this comment.
🐛 Correctness Issue
Breaking Change: Removed Custom Context Handler Support.
The change eliminates support for custom context functions, which can break applications relying on this feature for specialized routing behavior.
Current Code (Diff):
- _, err = c.app.next(c)
+ if c.app.newCtxFunc != nil {
+ _, err = c.app.nextCustom(c)
+ } else {
+ _, err = c.app.next(c)
+ }📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| _, err = c.app.next(c) | |
| if c.app.newCtxFunc != nil { | |
| _, err = c.app.nextCustom(c) | |
| } else { | |
| _, err = c.app.next(c) | |
| } |
| // AcquireCtx retrieves a new Ctx from the pool. | ||
| func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) Ctx { | ||
| ctx, ok := app.pool.Get().(Ctx) | ||
| func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) CustomCtx { |
There was a problem hiding this comment.
🐛 Correctness Issue
Breaking API change: Return type modification.
Changing the return type of AcquireCtx from Ctx to CustomCtx will break existing code that expects the Ctx interface type.
Current Code (Diff):
+ func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) CustomCtx {
- func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) Ctx {📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) CustomCtx { | |
| func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) Ctx { |
🔄 Dependencies Affected
app_test.go
Function: TestApp
Issue: Type assertion to (*DefaultCtx) will fail if CustomCtx is not compatible with DefaultCtx
Suggestion: Update type assertions or ensure CustomCtx is compatible with DefaultCtx
Proposed Code:
c, _ := app.AcquireCtx(fctx).(*DefaultCtx)
c, _ := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
|
|
||
| // ReleaseCtx releases the ctx back into the pool. | ||
| func (app *App) ReleaseCtx(c Ctx) { | ||
| func (app *App) ReleaseCtx(c CustomCtx) { |
There was a problem hiding this comment.
🐛 Correctness Issue
Breaking API change: Parameter type modification.
Changing the parameter type of ReleaseCtx from Ctx to CustomCtx will break existing code that passes Ctx interface instances.
Current Code (Diff):
+ func (app *App) ReleaseCtx(c CustomCtx) {
- func (app *App) ReleaseCtx(c Ctx) {📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| func (app *App) ReleaseCtx(c CustomCtx) { | |
| func (app *App) ReleaseCtx(c Ctx) { |
🔄 Dependencies Affected
app.go
Function: Unknown
Issue: Existing code calls ReleaseCtx with Ctx interface instances
Suggestion: Update all callers to use CustomCtx or keep the original parameter type
Proposed Code:
defer app.ReleaseCtx(c)
app_test.go
Function: Unknown
Issue: Multiple test functions call ReleaseCtx with Ctx interface instances
Suggestion: Update all test callers to use CustomCtx or keep the original parameter type
Proposed Code:
app.ReleaseCtx(c)
bind_test.go
Function: Unknown
Issue: Test code calls ReleaseCtx with Ctx interface instances
Suggestion: Update test code to use CustomCtx or keep the original parameter type
Proposed Code:
defer app.ReleaseCtx(c)
PR Summary
Streamline Context API and Enhance HTTP Standards Compliance
Overview
This PR refactors custom context handling with a new simplified API (
NewWithCustomCtx) while improving HTTP standards compliance across several components. It enhances cookie handling, authentication security, header parsing, and adds expanded test coverage.Change Types
NewWithCustomCtxAffected Modules
app.goNewWithCustomCtx, simplified handlers, renamed internal functionsctx.go/ctx_interface.gorouter.gobasicauth/cache/helpers.gostate.goNotes for Reviewers
NewWithCustomCtxfunction replacing separateNew()andNewCtxFunc()calls