Commit Graph

85 Commits (main)

Author SHA1 Message Date
Kashiwa e90fe8afbc
♻️Refactor: remove redundant field `method` in `DefaultCtx` (#3372)
* ♻️Refactor: remove redundant field method in defaultCtx

* ♻️Refactor: rename getMethodINT to getMethodInt
2025-03-26 13:16:53 +01:00
Kashiwa 4bf292945d
♻️Refactor: reduce DefaultCtx from 736 to 728 bytes (#3368) 2025-03-25 08:30:41 +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
Kashiwa 6afba957f1
🩹 Fix: sorting error in sortAcceptedTypes (#3331)
* 🩹 Fix: correct sorting error in sortAcceptedTypes.

* ♻️ Refactor: remove redundant branch

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-01 18:14:50 +01:00
Kashiwa 0d1ade4626
♻️ Refactor: Improve Performance of getSplicedStrList (#3318)
* ♻️ Refactor: improve performance of getSplicedStrList

goos: linux
goarch: amd64
pkg: github.com/gofiber/fiber/v3
cpu: AMD EPYC 7763 64-Core Processor
                           │   old.txt   │               new.txt               │
                           │   sec/op    │   sec/op     vs base                │
_Utils_GetSplicedStrList-4   66.12n ± 1%   51.05n ± 1%  -22.79% (p=0.000 n=50)

                           │  old.txt   │            new.txt             │
                           │    B/op    │    B/op     vs base            │
_Utils_GetSplicedStrList-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=50) ¹
¹ all samples are equal

                           │  old.txt   │            new.txt             │
                           │ allocs/op  │ allocs/op   vs base            │
_Utils_GetSplicedStrList-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=50) ¹
¹ all samples are equal

* 🚨 Test: add more test for getSplicedStrList

* 🩹 Fix: golangci-lint ifElseChain

* ♻️ Refactor: use more descriptive variable names
2025-02-24 08:13:47 +01:00
Kashiwa b1e858bc76
♻️ Refactor: the value of map is unused in uniqueRouteStack (#3320)
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-02-24 08:12:05 +01:00
Kashiwa 283ef32196
🩹 Fix: genericParseType parsing large uint leads to overflow (#3315)
* 🩹 Fix: genericParseType parsing large uint leads to overflow

* ♻️ Refactor: use strconv.FormatUint instead of fmt.Sprintf
2025-02-20 12:26:35 +01:00
René f5b7a12d84 cleanup: remove unused function `IndexRune` 2025-01-30 16:50:20 +01:00
Giovanni Rivera 4e5fea1d7a
🩹 Fix: Fix app.Test() auto-failing when a connection is closed early (#3279)
* ♻️ Refactor: Extract testConn err to variable

* ♻️ Refactor: Extract ErrTestGotEmptyResponse from app.Test()

* 🩹 Fix: Fix `app.Test()` auto-failing when testConn is closed

* 🩹 Fix(app_test.go): Use tab for indent instead of spaces

* 🩹 Fix(app_test.go): Fix to respect gofmt linter

* ♻️ Refactor: Update Drop tests to verify error type
2025-01-13 14:18:03 +01:00
Giovanni Rivera f8b490f89e
🔥 Feature: Add TestConfig to app.Test() for configurable testing (#3161)
* 🔥 Feature: Add thread-safe reading from a closed testConn

* 🔥 Feature: Add TestConfig to app.Test()

This commit is summarized as:
- Add the struct `TestConfig` as a parameter for `app.Test()` instead of `timeout`
- Add documentation of `TestConfig` to docs/api/app.md and in-line
- Modify middleware to use `TestConfig` instead of the previous implementation

Fixes #3149

* 📚 Doc: Add more details about TestConfig in docs

* 🩹 Fix: Correct testConn tests

- Fixes Test_Utils_TestConn_Closed_Write
- Fixes missing regular write test

* 🎨 Style: Respect linter in Add App Test Config

* 🎨 Styles: Update app.go to respect linter

* ♻️ Refactor: Rename TestConfig's ErrOnTimeout to FailOnTimeout

- Rename TestConfig.ErrOnTimeout to TestConfig.FailOnTimeout
- Update documentation to use changed name
  - Also fix stale documentation about passing Timeout as a
    single argument

* 🩹 Fix: Fix typo in TestConfig struct comment in app.go

* ♻️ Refactor: Change app.Test() fail on timeouterror to os.ErrDeadlineExceeded

* ♻️ Refactor:Update middleware that use the same TestConfig to use a global variable

* 🩹 Fix: Update error from FailOnTimeout to os.ErrDeadlineExceeded in tests

* 🩹 Fix: Remove errors import from middlware/proxy/proxy_test.go

* 📚 Doc: Add `app.Test()` config changes to docs/whats_new.md

* ♻ Refactor: Change app.Test() and all uses to accept 0 as no timeout instead of -1

* 📚 Doc: Add TestConfig option details to docs/whats_new.md

* 🎨 Styles: Update docs/whats_new.md to respect markdown-lint

* 🎨 Styles: Update docs/whats_new.md to use consistent style for TestConfig options description

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-11-22 08:43:38 +01:00
Juan Calderon-Perez f668537c02
chore: Bump golangci-lint to v1.60.3 (#3119)
Bump golangci-lint to v1.60.3
2024-09-02 15:38:59 +02:00
RW fadedcb5be
Use utils Trim functions instead of the strings/bytes functions (#3087)
* Use utils Trim functions instead of the strings/bytes functions

* rename Test and Benchmark functions with same name
2024-07-24 16:25:35 +02:00
Juan Calderon-Perez 486304d050
v3: Improve performance of helper functions (#3086)
* Improve performance of helper functions

* Fix issue with PR comments from forks
2024-07-23 21:32:22 +02:00
Juan Calderon-Perez 8c3f81e2b7
v3: Use Named Fields Instead of Positional and Align Structures to Reduce Memory Usage (#3079)
* Use composites for internal structures. Fix alignment of structures across Fiber

* Update struct alignment in test files

* Enable alignment check with govet

* Fix ctx autoformat unit-test

* Revert app Config struct. Add betteralign to Makefile

* Disable comment on alert since it wont work for forks

* Update benchmark.yml

* Update benchmark.yml

* Remove warning from using positional fields

* Update router.go
2024-07-23 08:37:45 +02:00
RW 046b4a9d4e
Adding a generator to generate the CTX interface (#3024) 2024-06-03 08:37:22 +02:00
RW 077968abec
[v3 Maintenance]: Consolidate and Document Core Changes in v3 (#2934)
* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3

* [v3 Maintenance]: Consolidate and Document Core Changes in v3
2024-04-23 08:18:19 +02:00
deferdeter 2f8ff5662d
chore: fix some struct names in comments (#2974)
Signed-off-by: deferdeter <deferdeter@outlook.com>
2024-04-16 08:15:13 +02:00
Behzad Khokher 5e8df0a348
feat(middleware/cors): Add support for Access-Control-Allow-Private-Network (#2908)
* Add support for Access-Control-Allow-Private-Network in CORS middleware

* Access-Control-Allow-Private-Network in CORS middleware documentation update

* Access-Control-Allow-Private-Network in CORS middleware tests

* Fix lint issues

* Fix formatting

* Rename config option, add more unit-tests

* Fix syntax issue

* Fix conditional

* Fix formatting, add more unit-tests

* chore(middleware/cors): Update middleware/cors/cors.go

* chore(middleware/cors): add HeaderAccessControlRequestPrivateNetowkr

* test(middleware/cors): fix CORS headers

* docs(middleware/cors): table order and alignment

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
Co-authored-by: Jason McNeil <sixcolors@mac.com>
2024-03-22 12:18:12 +01:00
nickajacks1 82070cb4c8
chore: Update golangci-lint to enable more lint rules (#2923)
* chore(lint): enable ifElseChange and clean up config a bit

* chore(lint): enable gocritic diagnostic checks
2024-03-18 14:50:40 +01:00
nickajacks1 8ca562c92e
♻️Refactor: Simplify content negotiation code (#2865)
* refactor: Update to use fasthttp.VisitHeaderParams

The implementation of forEachParameter was upstreamed to fasthttp, so
use that version instead of maintaining our own.

* refactor: use map for header params

The previous implementation of content negotiation used some difficult
to understand techniques in order to reduce allocations, potentially
hurting maintainability. The more natural approach for storing and
comparing unordered media-type parameters is to utilize maps. While the
resulting code still isn't as simple as it could be, it's a step closer.

To reduce allocations, we use a sync.Pool. This actually reduces in fewer
allocations than before at 3 or more parameters. The net result is nearly
identical performance for zero parameters, almost-as-good performance for
1-2 parameters, and better performance for 3+ parameters.

---------

Co-authored-by: Jason McNeil <sixcolors@mac.com>
2024-02-19 15:28:06 +01:00
nickajacks1 4c68e0242d
ci: address multiple lint rules (#2869)
* ci: explicitly disable tagalign

Tagalign requires awkward manual formatting and doesn't provide much
value for readability.

* ci: enable mirror linter

mirror warns against certain cases of useless conversion between string
and []byte.

* ci: enable perfsprint linter

This linter encourages replacing several functions from the fmt package
with faster alternatives. While fixing issues, I also added a few
exported error types rather than returning a naked errors.New().
2024-02-19 14:33:10 +01:00
Juan Calderon-Perez 9dabf96ddc
Bump golangci-lint to v1.56.1 (#2842)
* Update linter.yml

* Disable spancheck, fix some of the errors

* Fix ErrorAs, disable go-require from testifylint

* Remove extra space

* Fix all warnings from golangci-lint and revive unused params

* Refactor CopyContextToFiberContext

* Update adaptor.go
2024-02-13 08:23:15 +01:00
Muhammed Efe Cetin 6ea4d81331
Merge branch 'master' into v3-beta 2023-11-07 20:22:31 +03:00
nickajacks1 cbcb1aec0a
feat: add support for parameters in content negotiation (#2678)
*  feat: add support for parameters in content negotiation

Attempts to approach the level of support offered by express,
but behavior may differ in unusual corner cases.
Some key behaviors from Express that are implemented:
 - If an offer does not have every parameter listed in the given Accept,
   it is rejected.
 - Parameters do not affect specificity.
 - In a given specificity, more parameters gives greater precedence
 - Parameters are unordered
 - Matching is case-insensitive
 - Surrounding quotes for parameter values are stripped
 - If an Accept type specifies a parameter more than once, the last
   value provided is taken.
 - Parameters after q are not processed.

https://www.rfc-editor.org/rfc/rfc9110#name-parameters

* doc: properly attribute reader.go for validHeaderFieldByte

* fix: remove underscores from fuzz test name

* test(forEachParameter): improve coverage

* doc: add comment clarifying RFC 9110 non-compliance for corner case
2023-11-07 08:25:23 +01:00
Josh Larsen 8c69065e83
📚 [Doc] fix incorrect status code source (#2667)
* fix incorrect status code source

* fix typo
2023-10-10 08:11:18 +02:00
João Victor Oliveira Couto f29f39b1b3
fix: Decompress request body when multi Content-Encoding sent on request headers (#2555)
* 🔧 feat: Decode body in order when sent a list on content-encoding

* 🚀 perf: Change `getSplicedStrList` to have 0 allocations

* 🍵 test: Add tests for the new features

* 🍵 test: Ensure session test will not raise an error unexpectedly

* 🐗 feat: Replace strings.TrimLeft by utils.TrimLeft

Add docs to functions to inform correctly what the change is

* 🌷 refactor: Apply linter rules

* 🍵 test: Add test cases to the new body method change

* 🔧 feat: Remove return problems to be able to reach original body

* 🌷 refactor: Split Body method into two to make it more maintainable

Also, with the previous fix to problems detected by tests, it becomes really hard to make the linter happy, so this change also helps in it

* 🚀 perf: Came back with Header.VisitAll, to improve speed

* 📃 docs: Update Context docs
2023-08-06 17:23:37 +02:00
Muhammed Efe Cetin 75bb02b87e
Merge remote-tracking branch 'origin/master' into v3-beta 2023-08-05 22:02:01 +03:00
Jiun Lee fefc533834
🚀 Add Logger interface and fiberlog (#2499)
* add log for fiber

* replace log in fiber

* add Log use to adapt for log libraries

* Update app.go

Co-authored-by: Tomás Warynyca <41587659+tomaswarynyca@users.noreply.github.com>

* wip: add log docs

* add WithLogger use to print key and value

* remove CtxLogger and add WithContext use to bind Context

* fix errcheck

* fix errcheck

* update log.md

---------

Co-authored-by: Tomás Warynyca <41587659+tomaswarynyca@users.noreply.github.com>
2023-06-26 08:16:57 +02:00
Jason McNeil 0f5ffed3cc
🐛fix: update getOffer to consider quality and specificity (#2486)
* feat: getOffer consider q value and specificity

* fix: ignore q=0

* fix: float

* test: client-prefered order and q=0 not acceptable

* fix: always use my insertion sort.

* fix: sort.SliceStable if > 20

* fix: zero allocations

* perf: optimize the sort

* chore: fix lint issue

* fix: consider order

* chore: fix test func name

* chore: fix helper test func name

* chore: revert fix

* perf: use fasthttp.ParseUfloat

* test: GetOffer and SortAcceptedTypes

* chore: remote nil check

* test: sortAcceptedTypes

* fix: use utils.UnsafeBytes

* docs: update docs for fiber PR #2486

* docs: update docs for fiber PR #2486

* test: add test from docs

* fix: yaml
2023-06-07 17:51:45 +02:00
RW 65e0ce285a
🐛 [Bug-Fix]: Mounted subapps don't work correctly if parent app attached … (#2331)
* 🐛 [Bug]: Mounted subapps don't work correctly if parent app attached additional middlewares after mounting (v2.40.1 bug) #2233
2023-04-13 14:19:04 +02:00
RW 28d9abb71b
Fix #2383, accepts mimeType (#2386)
* Fix #2383, accepts mimeType

* Fix #2383, accepts mimeType

* Fix #2383, accepts mimeType
2023-03-27 15:55:41 +02:00
Muhammed Efe Çetin 3168a60605
👷 v3 (ci): fix some linter warnings 2023-02-09 23:15:21 +03:00
Muhammed Efe Çetin 088cde594d
Merge remote-tracking branch 'origin/master' into v3-beta 2023-02-05 23:43:42 +03:00
leonklingele ac4ce21d9c
🐛 Bug: Fix issues introduced in linting PR (#2319)
* internal: revert linting changes

Changes to the internal package should not have been made in 167a8b5e94.

* middleware/monitor: revert changes to exported field "ChartJSURL"

This is a breaking change introduced in 167a8b5e94.

* middleware/monitor: fix error checking

Fix the errorenous error checking introduced in 167a8b5e94.

* 🐛 Bug: Fix issues introduced in linting PR #2319

* 🐛 Bug: Fix issues introduced in linting PR #2319

* Bug: Fix issues introduced in linting PR #2319

---------

Co-authored-by: René Werner <rene@gofiber.io>
2023-02-02 15:57:40 +01:00
leonklingele 167a8b5e94
🚀 Feature: Add and apply more stricter golangci-lint linting rules (#2286)
* golangci-lint: add and apply more stricter linting rules

* github: drop security workflow now that we use gosec linter inside golangci-lint

* github: use official golangci-lint CI linter

* Add editorconfig and gitattributes file
2023-01-27 09:01:37 +01:00
M. Efe Çetin 5406560033
🧹 chore: make most tests parallel (#2299)
* 🧹 chore: make most tests parallel

* revert some tests

* revert some tests

* revert some tests
2023-01-15 23:21:37 +08:00
leonklingele adcf92dec1
🚀 Feature: Add idempotency middleware (v2 backport) (#2288)
* 🚀 Feature: Add idempotency middleware (#2253)

* middleware: add idempotency middleware

* middleware/idempotency: use fiber.Storage instead of custom storage

* middleware/idempotency: only allocate data if really required

* middleware/idempotency: marshal response using msgp

* middleware/idempotency: add msgp tests

* middleware/idempotency: do not export response

* middleware/idempotency: disable msgp's -io option to disable generating unused methods

* middleware/idempotency: switch to time.Duration based app.Test

* middleware/idempotency: only create closure once

* middleware/idempotency: add benchmarks

* middleware/idempotency: optimize strings.ToLower when making comparison

The real "strings.ToLower" still needs to be used when storing the data.

* middleware/idempotency: safe-copy body

* middleware/idempotency: backport to v2
2023-01-13 08:38:50 +01:00
leonklingele 0b5a7d0425
🚀 Feature: Add idempotency middleware (#2253)
* middleware: add idempotency middleware

* middleware/idempotency: use fiber.Storage instead of custom storage

* middleware/idempotency: only allocate data if really required

* middleware/idempotency: marshal response using msgp

* middleware/idempotency: add msgp tests

* middleware/idempotency: do not export response

* middleware/idempotency: disable msgp's -io option to disable generating unused methods

* middleware/idempotency: switch to time.Duration based app.Test

* middleware/idempotency: only create closure once

* middleware/idempotency: add benchmarks

* middleware/idempotency: optimize strings.ToLower when making comparison

The real "strings.ToLower" still needs to be used when storing the data.

* middleware/idempotency: safe-copy body
2023-01-06 08:46:17 +01:00
Muhammed Efe Çetin c62dd16e8d
Merge remote-tracking branch 'origin/master' into v3-beta 2022-11-27 20:34:48 +03:00
RW e4b3b5c708
Improve interface for custom logger func (#2225)
* - logger: fix custom tag
- use real bytebufferpool dependency instead of the internal

* - logger: fix custom tag
- use real bytebufferpool dependency instead of the internal

* - logger: fix custom tag
- use real bytebufferpool dependency instead of the internal

* - logger: fix custom tag
- use real bytebufferpool dependency instead of the internal
2022-11-18 15:32:56 +01:00
Caleb Case 61b4496067
Track Configured Values (#2221)
* WIP: Use Parent Error Handler on Mount

* Add suggested boolean guard

* Move flag to App

* Move to copy of config as configured

* Apply the same trick to customMethod
2022-11-15 12:13:11 +01:00
leonklingele e388e0edb3
Update HTTP status codes (#2203)
* helpers: add HTTP status code 306

* helpers: show numeric HTTP status code instead of status code RFC next to errors

* utils: add HTTP status code 425

* helpers,utils: update list of HTTP status codes
2022-11-11 08:40:37 +01:00
Rafi Muhammad 878c9549d8
Feat: Register custom methods (#2107)
* Implementing register custom methods

* Return timout time to 1000

* Update app_test.go

* Change update stack to add custom request method

* Feat: Register custom methods #2107

* Feat: Register custom methods #2107

* update logic

* optimization.

* fix

Co-authored-by: Rafi Muhammad <rafi.muhammad@mekari.com>
Co-authored-by: RW <rene@gofiber.io>
Co-authored-by: Muhammed Efe Çetin <efectn@protonmail.com>
2022-11-11 08:23:30 +01:00
Muhammed Efe Çetin 9428befb9c
Merge remote-tracking branch 'origin/master' into v3-beta 2022-10-28 17:26:17 +03:00
Soham Sen 9a6002056c
Switch to text/javascript as per RFC9239 (#2146)
* Switch to text/javascript as per RFC9239

* Add deprecated flag to application/javascript
2022-10-10 14:29:51 +02:00
Jinquan Wang e8c93e6153
🐛 [Fix]: unhandle in strictmode (#2055)
* fix: unhandle in strictmode

* 🐛 fix: error test

*  chore: add testcases for strictrouting

*  chore: fix test case
2022-09-07 11:05:37 +02:00
Muhammed Efe Çetin 319b8ea3a8
Merge remote-tracking branch 'origin/master' into v3-beta 2022-09-03 23:56:45 +03:00
M. Efe Çetin cbfcac2c0a
🐛 bug: remove prefork support from custom listeners (#2060)
* 🐛 bug: remove prefork support from custom listeners

* Update listen_test.go
2022-08-30 13:01:24 +02:00
M. Efe Çetin aef7ea53b3
🐛 bug: fix route constraints problems (#2033)
* 🐛 bug: fix route constraints problems

* escape support for data

* exactLen -> len
2022-08-26 14:16:06 +02:00
Trim21 b161f805c2
v3(enhancement): remove `utils.Trim*` (#2030)
stdlib functions have same performance in go1.19
2022-08-20 13:52:09 +08:00