834 Commits

Author SHA1 Message Date
Muhammed Efe Cetin
c2ae40c6b8
fix linter 2025-07-07 14:39:18 +03:00
Muhammed Efe Cetin
2514afd3ce
feat: add context methods to fiber.Storage interface 2025-07-07 14:34:29 +03:00
RW
dd739687d3
Refactor fasthttp iter calls to range loops (#3559)
refactor: replace fastHTTP iter calls with for loops
2025-07-01 14:14:56 +02:00
dependabot[bot]
eddecf22e4
build(deps): bump github.com/valyala/fasthttp from 1.62.0 to 1.63.0 (#3557)
* build(deps): bump github.com/valyala/fasthttp from 1.62.0 to 1.63.0

Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.62.0 to 1.63.0.
- [Release notes](https://github.com/valyala/fasthttp/releases)
- [Commits](https://github.com/valyala/fasthttp/compare/v1.62.0...v1.63.0)

---
updated-dependencies:
- dependency-name: github.com/valyala/fasthttp
  dependency-version: 1.63.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump github.com/valyala/fasthttp from 1.62.0 to 1.63.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: René <rene@gofiber.io>
2025-07-01 11:06:50 +02:00
Juan Calderon-Perez
d79fa01f0f
🐛 bug: Fix Content-Disposition header per RFC 6266 (#3551)
* Use raw UTF-8 filenames in Content-Disposition

* Fix lint issues

* Fix issue with new funct

* Improve and fix quoteRawString

* fix issues

* Fix lint issues

* fix golangci-lint

* Update static_test.go

* Update static_test.go
2025-06-30 09:06:11 +02:00
Juan Calderon-Perez
bdd9e22bd7
🐛 bug: Fix Cache middleware handling of Age (#3547)
* Revert benchmark loop changes

* test: cover Age header parsing

* generate msgp files

* Update cache.go

* Cast result

* Update cache.go
2025-06-30 09:04:35 +02:00
Juan Calderon-Perez
b08d0bfd2f
🐛 bug: Fix Cache-Control header parsing (#3534)
* 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>
2025-06-23 07:42:12 +02:00
Juan Calderon-Perez
e1a7c114b2
🧹 chore: Improve CSRF tests coverage (#3531)
test(csrf): cover cookie config warnings
2025-06-20 08:47:57 +02:00
Juan Calderon-Perez
6d16bf5605
🧹chore: Improve BasicAuth middleware default security (#3522)
* Refine BasicAuth middleware

* Fix lint issues

* Update basicauth.md
2025-06-20 08:47:35 +02:00
Juan Calderon-Perez
aea0fd230f
🧹 chore: Improve CORS tests coverage (#3530)
* test(cors): warn when all origins and func

* Fix linter issue
2025-06-20 08:47:05 +02:00
Juan Calderon-Perez
528462d2bd
🧹 chore: Add missing CSRF token extractor tests (#3527)
test: cover missing form error
2025-06-18 08:25:05 +02:00
Juan Calderon-Perez
a35c5d2e15
🧹 chore: Improve Helmet middleware tests coverage (#3523)
* test: add HSTS coverage

* Update middleware/helmet/helmet_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update helmet_test.go

* Update helmet_test.go

* Revert test changes

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-06-17 23:24:49 +02:00
Juan Calderon-Perez
0590709556
🧹 chore: Improve Idempotency middleware tests coverage (#3521)
* Consolidate idempotency tests

* Fix lint issues

* Fix more lint issues

* Fix lint issue
2025-06-16 17:45:40 +02:00
Juan Calderon-Perez
1ce3182951
🧹 chore: Improve EarlyData middleware tests coverage (#3520)
* test: move config tests into earlydata_test

* Fix lint issue
2025-06-16 17:44:32 +02:00
Jason McNeil
670fbd5e45
feat: Add support for Keys() in session middleware (#3517)
*  feat: Update session middleware add Keys method and update docs to match key type any

*  test: Add /keys endpoint to set and retrieve multiple session keys

*  test: Refactor /keys endpoint to trim whitespace and improve key handling in session tests
2025-06-13 11:40:17 +02:00
Juan Calderon-Perez
b29171ce40
🧹 chore: Improve CORS middleware response headers (#3505)
* Improve CORS middleware

* 🐛 fix: Remove unused 'slices' import from CORS middleware

---------

Co-authored-by: Jason McNeil <sixcolors@mac.com>
2025-06-10 08:47:34 +02:00
Juan Calderon-Perez
3a60cf7a4e
🧹 chore: Refactor EnvVar middleware (#3513)
* remove ExcludeVars option

* Simplify envvar export logic
2025-06-10 08:40:58 +02:00
Juan Calderon-Perez
80f4f99c01
🧹 chore: Fix typos in code and docs (#3507)
chore: fix spelling mistakes across codebase
2025-06-07 22:34:44 +02:00
Juan Calderon-Perez
5eb1432c81
🐛 fix: Middlewares immutable config handling (#3494)
* Respect immutable flag in middlewares

* Add unit-tests for Immutable
2025-06-01 13:53:18 +02:00
Juan Calderon-Perez
09d9e169b2
🧹 chore: Enhance config validation in EncryptCookie middleware (#3491)
* test: validate encryptcookie config key

* simplified logic and remove duplicated code

* remove extra spaces
2025-05-28 15:12:57 +02:00
Juan Calderon-Perez
a779888d44
🧹 chore: Improve cache middleware RFC compliance (#3488)
* test: cover cache enhancements

* Fix lint issues and tests names

* Fix test

* Use utils.ToLower()

* Use utils.Trim

* Add missing param
2025-05-28 13:59:06 +02:00
Oleksandr Redko
956205311b
♻️ refactor: use maps.Copy to simplify code (#3490) 2025-05-28 12:49:33 +02:00
tongjicoder
557095b094
♻️ refactor: use slices.Contains to simplify code (#3486)
refactor: use slices.Contains to simplify code

Signed-off-by: tongjicoder <tongjicoder@icloud.com>
2025-05-27 20:03:22 +02:00
Jason McNeil
7559758b02
🧪 test: Enhance CSRF tests to address unsafe header value issue (#2045) (#3485)
* 🧪 test: Enhance CSRF tests to address unsafe header value issue (#2045)

* Update middleware/csrf/csrf_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-27 19:18:25 +02:00
Juan Calderon-Perez
47f47ae2d8
🧹 chore: Enhance BasicAuth middleware to better comply with RFC 6750 (#3484)
* test(basicauth): ensure whitespace tolerant

* use utils.TrimSpace

* Update docs
2025-05-27 14:27:45 +02:00
Juan Calderon-Perez
804a2b923e
🧹 chore: Enhance KeyAuth middleware to better comply with RFC 6750 (#3482)
* docs(keyauth): add Realm option

* Add unit-test for GenericError case

* Update keyauth_test.go

* Backport fixes

* Update keyauth_test.go

* Fix spacing

* Add test for empty value

* Remove extra comma

* Add missing closing brace

* Review comments

* add missing import

* Add more unit-tests

* remove inconclusive test
2025-05-27 14:07:42 +02:00
RW
c2eee63183
🧹 chore: Update minimum go version to 1.24 (#3481)
* chore: update docs and workflows for go1.24

* Fix listen bug

* Use b.Loop() for benchmarks https://go.dev/blog/testing-b-loop

* Use b.Loop() for benchmarks https://go.dev/blog/testing-b-loop

* Revert b.Loop() for some benchmarks

* Change genericParser benchmarks (runParallel)

* Change Benchmark_Router_Github_API benchmarks (runParallel)
2025-05-27 13:23:02 +02:00
pj
9bd7a1c50d
feat: fiber.Context implement context.Context (#3382)
* Ctx implements context.Context

* fix up some linting issues

* added some tests

* no message

* fiber.Ctx implements context.Context

* no message

* implement compile-time check

* update formatting

* update compile-time checks

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-05-26 08:53:18 +02:00
RW
e722d82206
️ Performance optimizations (#3477)
adpater / HTTPHandler
NEW
Benchmark_HTTPHandler-12    	 1762837	       640.6 ns/op	     696 B/op	      10 allocs/op
Benchmark_HTTPHandler-12    	 1924524	       616.5 ns/op	     696 B/op	      10 allocs/op
Benchmark_HTTPHandler-12    	 1838780	       650.4 ns/op	     696 B/op	      10 allocs/op
Benchmark_HTTPHandler-12    	 1876947	       644.0 ns/op	     696 B/op	      10 allocs/op
OLD
Benchmark_HTTPHandler-12    	 1864819	       667.2 ns/op	     720 B/op	      11 allocs/op
Benchmark_HTTPHandler-12    	 1892569	       677.0 ns/op	     720 B/op	      11 allocs/op
Benchmark_HTTPHandler-12    	 1811704	       639.5 ns/op	     720 B/op	      11 allocs/op
Benchmark_HTTPHandler-12    	 1879849	       644.0 ns/op	     720 B/op	      11 allocs/op

Utils / IsNoCache
NEW
Benchmark_Utils_IsNoCache-12    	44307204	        27.08 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	40782919	        26.88 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	44228217	        26.69 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	45605700	        26.75 ns/op	       0 B/op	       0 allocs/op
OLD
Benchmark_Utils_IsNoCache-12    	30043908	        37.80 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	32137476	        37.51 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	31474653	        37.92 ns/op	       0 B/op	       0 allocs/op
Benchmark_Utils_IsNoCache-12    	31838683	        37.71 ns/op	       0 B/op	       0 allocs/op
2025-05-25 17:23:03 +02:00
dependabot[bot]
3ff2d378ab
build(deps): bump github.com/valyala/fasthttp from 1.60.0 to 1.62.0 (#3440)
* build(deps): bump github.com/valyala/fasthttp from 1.60.0 to 1.62.0

Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.60.0 to 1.62.0.
- [Release notes](https://github.com/valyala/fasthttp/releases)
- [Commits](https://github.com/valyala/fasthttp/compare/v1.60.0...v1.62.0)

---
updated-dependencies:
- dependency-name: github.com/valyala/fasthttp
  dependency-version: 1.62.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix CSRF middleware tests for fasthttp 1.62 (#3471)

Fix CSRF tests for fasthttp 1.62

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: RW <rene@gofiber.io>
2025-05-24 11:21:50 +02:00
RW
aae8892c7e
Improve proxy middleware (#3468) 2025-05-23 10:47:05 +02:00
Juan Calderon-Perez
18ed68b543
🧹 chore: Fix proxy middleware tests for offline environments (#3467)
* Fix proxy middleware tests to avoid external network

* Update proxy_test.go

* Update middleware/proxy/proxy_test.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update proxy_test.go

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-22 14:07:06 +02:00
RW
119743b726
🚀 Improve routing treeBuild flow (#3456)
* improve routing treeBuild flow

* improve routing treeBuild flow
2025-05-16 08:30:05 +02:00
Isaac Andrade
4321dfed55
♻️ refactor: Change c.Redirect() default status (#3415)
* Set default redirect response status to 303 SeeOther

Closes #3405

In some browsers, redirect status 302 Found sometimes is used to change
the HTTP verb of the response from what the user set to what was used in
the request. Changing to 303 SeeOther in the default works more like
expected: it defaults to GET and can be overriden by the user.

* Add tests to Redirect default status change.

* Update docs.

* Fix remaining tests to reflect redirect 303 status as the new default. Reflect that in docs/whats_new.md

* Update redirect_test.go

* Fix code review hints

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: René <rene@gofiber.io>
2025-05-12 14:56:23 +02:00
Yorick de Wid
057647a579
🔥 feat: Add support for ForceColors in Logger middleware (#3428)
* Force the use of terminal colors via config option

* docs: add example for forcing terminal colors in logger middleware

* test: add benchmarks for logger middleware with forced colors

* Add ForceColors field to 'whats new'

* Show example in 'whats new'
2025-05-09 13:58:41 +02:00
Jason McNeil
b3e84860d2
Revert "🔥 feat: Add Context Support to RequestID Middleware" (#3365)
Revert "🔥 feat: Add Context Support to RequestID Middleware (#3200)"

This reverts commit f725ded92bac13e773f92ff478e1a461c160abd3.

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-04-08 08:59:24 +02:00
RW
62b099879a
🧪 fix: Logger Middleware tests to use regex for time validation (#3392)
* test: rewrite logger format tests to use regex for time validation

* test: rewrite logger format tests to use regex for time validation
2025-04-03 13:36:30 +02:00
Jason McNeil
bb12633c8b
Revert "🔥 feat: Add support for context.Context in keyauth middleware" (#3364)
Revert "🔥 feat: Add support for context.Context in keyauth middleware (#3287)"

This reverts commit 4177ab4086a97648553f34bcff2ff81a137d31f3.

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-31 16:55:01 +02:00
Juan Calderon-Perez
75281bd874
🧹 chore: Simplify HealthCheck middleware (#3380)
* Simplify middleware

* Rename default endpoints
2025-03-30 11:46:52 +02:00
Edvard
e947e03ed2
🔥 feat(logger): Add predefined log formats (#3359)
* feat(logger): Add predefined log formats

This commit introduces predefined log formats for the logger middleware, enhancing its flexibility and ease of use. Users can now specify formats like "common", "combined", and "json" in addition to the default format.

Changes:

- Added a `format.go` file to store predefined log format constants.
- Updated `config.go` to include documentation for the `Format` configuration option, explaining the available placeholders and predefined formats.
- Modified `logger.go` to utilize the predefined formats based on the `Format` configuration.
- Added a new test case `Test_Logger_CLF` in `logger_test.go` to verify the "common" log format.

* feat(logger): Use predefined formats and fix default format

This commit updates the logger middleware to utilize the predefined log formats introduced in a previous commit. It also fixes the default format to use the `FormatDefault` constant.

Changes:

-   Updated `config.go` to use `FormatDefault` constant for the default format.
-   Updated `default_logger.go` to use `FormatDefault` constant for the default format.
-   Added new test cases in `logger_test.go` to verify the "common", "combined" and "json" log formats.
-   Updated `format.go` to add newline character to the end of the default format.

* feat(logger): Document and exemplify predefined formats

* fix(logger): Improve test assertions based on golangci-lint

* docs(logger): Improve documentation and formatting logger.md based on markdownlint-cli2

* docs(logger): Improve documentation based on markdownlint-cli2

* fix(logger): Improve combined and JSON format tests

* feat(logger): Add ECS log format

* feat(logger): Add CustomFormat option

This commit introduces a `CustomFormat` option to the `Config` struct, allowing users to specify a predefined format (like "common", "combined", "json", or "ecs")

* feat(logger): Add ECS log format to examples and config

* docs(logger): Update examples in whats_new.md

* feat(logger): Remove CustomFormat option and renamed Format consts

-   Removed `CustomFormat` field from `Config`.
-   Removed `LoggerConfig` map.
-   Rename predefined formats constants.

* docs(logger): Update documentation and examples after format refactor

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-21 16:13:21 +01:00
Oleksandr Redko
f6ac929fde
🧹 chore: Mark unused tests with t.SkipNow (#3366)
* 🚨 test: uncomment test and mark it with t.SkipNow

* fix lint issues
2025-03-20 14:35:59 +01:00
Juan Calderon-Perez
395c8fafa9
🧹 chore: Fix linter workflow failures (#3354)
* Fix linter workflow failures

* Bump golang.org/x/net to v0.36.0

* Try skipping golangci-lint cache

* Update linter.yml

* fix: directives and spaces

* fix: better configuration

* fix: golangci-lint install

* Update golangci-lint version

* Enable SA4023

* Update golangci-lint config

* Remove duplicated rule

---------

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2025-03-17 08:29:51 +01:00
耗子
eb7b00b4fb
fix: default value comment 2025-03-13 01:44:57 +08:00
JIeJaitt
c0599ee1d4
🔥 feat: Add Skip function to logger middleware (#3333)
* 🔥 Feature(logger): Add Filter option to logger middleware

* 📚 Doc(logger): Clarify Filter middleware description

* 🚨 Test(logger): Enhance logger filter test with parallel subtests

* 🔒 Test(logger): Add mutex to prevent race conditions in logger test

* 🔥 Feature(logger): Add Filter option to logger middleware

* 📚 Doc(logger): Clarify Filter middleware description

* 🚨 Test(logger): Enhance logger filter test with parallel subtests

* 🔒 Test(logger): Add mutex to prevent race conditions in logger test

* 🚨 Test(logger): Refactor logger test to improve test isolation

* Fix issue with unit-tests

* Update middleware/logger/logger_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Apply logger filter as soon as possible

* 📚 Doc: Add logger filter configuration example to whats_new.md

* 📚 Doc: Update logger filter documentation in whats_new.md

* 📚 Doc: Update logger filter documentation and examples

* 🩹 Fix: improve what_new.md

* Update logic for Filter() in Logger middleware. Add more unit-tests

* Rename fields to match expressjs/morgan

* Update middleware/logger/default_logger.go

---------

Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: RW <rene@gofiber.io>
2025-03-10 09:06:11 +01:00
vinicius
4177ab4086
🔥 feat: Add support for context.Context in keyauth middleware (#3287)
* feat(middleware): add support to context.Context in keyauth middleware

pretty straightforward option to use context.Context instead of just
fiber.Ctx, tests added accordingly.

* fix(middleware): include import that was missing from previous commit

* fix(middleware): include missing import

* Replace logger with panic

* Update keyauth_test.go

* Update keyauth_test.go

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-07 08:23:24 +01:00
Kashiwa
ef4effc8a0
♻️ Refactor: Reduce the Memory Usage of ignoreHeaders (#3322)
♻️ Refactor: reduce the memory usage of ignoreHeaders

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-02-24 08:12:47 +01:00
Juan Calderon-Perez
e7c1b3e5e2
Add new config option 2025-02-23 16:00:39 -05:00
miyamo2
8970f515dd
🐛 fix: Align cache middleware with RFC7231 (#3283)
* 🩹 Fix(v3;middleware/cache): don't cache if status code is not cacheable

* allow 418 TeaPot

* fix test

* fix lint error

* check cacheability with map

* documentation

* fix: markdown lint

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-01-20 08:22:51 +01:00
RW
bc37f209bf
refactor(timeout): unify and enhance timeout middleware (#3275)
* feat(timeout): unify and enhance timeout middleware

- Combine classic context-based timeout with a Goroutine + channel approach
- Support custom error list without additional parameters
- Return fiber.ErrRequestTimeout for timeouts or listed errors

* feat(timeout): unify and enhance timeout middleware

- Combine classic context-based timeout with a Goroutine + channel approach
- Support custom error list without additional parameters
- Return fiber.ErrRequestTimeout for timeouts or listed errors

* refactor(timeout): remove goroutine-based logic and improve documentation

- Switch to a synchronous approach to avoid data races with fasthttp context
- Enhance error handling for deadline and custom errors
- Update comments for clarity and maintainability

* refactor(timeout): add more test cases and handle zero duration case

* refactor(timeout): add more test cases and handle zero duration case

* refactor(timeout): add more test cases and handle zero duration case

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-01-08 08:19:20 +01:00
Bulat Bagaviev
775e0a73f3
🩹 Fix: Memory leak removal in the idempotency middleware (#3263)
* 🩹 Fix: Add key removal in MemoryLock

* Fixed concurrent deletion.

* Fix: idempotency middleware's MemoryLock

* Add MemoryLock benchmarks.

* Updated benchmarks: Add returning error handling

* Renamed benchmark: RepeatedKeys

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-12-28 14:29:31 +01:00