Commit Graph

75 Commits (renanbastos93improve-error-handling-csrf-middle)

Author SHA1 Message Date
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
Muhammed Efe Çetin 4105b008c2
Merge remote-tracking branch 'origin/master' into v3-beta 2022-08-19 14:33:31 +03:00
Muhammed Efe Çetin cadd6014bb
v3: cleanup & update deps 2022-08-17 23:01:59 +03:00
M. Efe Çetin 2517944c80
feature: route constraints (#1998)
* Segment parameters constraints and determining it's type

* add parsing for constraints.

* fix tests

* add tests, benchs & some fixes.

* fix regex & datetime tests.

* clean up constraint parser, multiple constraint support.

* update

* regex customization.

* constants, remove variadic methods.

* add some benchs, refactor constraint check funtion.

* more readable conditions

* fix tests

* precompile regex

* precompile regex when parsing the route

* update comments
Co-authored-by: wernerr <rene@gofiber.io>

Co-authored-by: Mohab Abd El-Dayem <mohab.m.mohamed@gmail.com>
Co-authored-by: RW <rene@gofiber.io>
2022-08-16 08:05:50 +02:00
M. Efe Çetin 41159296f3
v3: revert " v3 (feature): use any as default Message type of Error struct (#1925)" (#2000)
Revert " v3 (feature): use any as default Message type of Error struct (#1925)"
2022-08-08 08:21:00 +02:00
M. Efe Çetin adcb1f2bf1
v3: fix benchmark results (#1982)
* v3: fix benchmark results

* v3: fix benchmark results

* Fix Benchmark_Router_Github_API

* reduce duplicated tests run actions

* reduce duplicated tests run actions

* fix some benchmarks

Co-authored-by: wernerr <rene@gofiber.io>
2022-08-07 14:53:01 +03:00
M. Efe Çetin a458bd344c
v3 (feature): convert fiber.Ctx type to interface (#1928)
*  v3: convert fiber.Ctx type to interface

* update ctx methods

* add new methods to customize ctx, fix some problems

* update comments.

* fix something
2022-07-13 07:48:29 +02:00
M. Efe Çetin e35a594cf1
v3 (feature): use any as default Message type of Error struct (#1925)
*  v3: use any as default Message type of Error struct.

*  v3: use any as default Message type of Error struct.

*  v3: use any as default Message type of Error struct.

*  v3: use any as default Message type of Error struct.
2022-06-12 18:37:23 +02:00
Muhammed Efe Çetin 8a15f77fc4
v3: move most deps to go.mod 2022-06-02 17:37:53 +03:00
Muhammed Efe Çetin edd89de2d6
v3: remove deprecations 2022-05-31 17:50:31 +03:00
Muhammed Efe Çetin 1188144d78
🎉 v3: init 2022-05-31 17:35:49 +03:00