Commit Graph

341 Commits (revert-3287-context-middleware)

Author SHA1 Message Date
Mazyar Yousefiniyae shad 7606c618d3
📚 Doc: Add more validation examples (#3369)
* add examples on valudator guid

* ref: return prev validation comment
2025-03-25 08:25:56 +01: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
Juan Calderon-Perez b56a141d59
docs: Update helmet.md default values (#3350)
Update helmet.md
2025-03-14 07:51:34 +01: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
nickajacks1 64c1771c26
🔥 Feature: Add Req and Res API (#2894)
* 🔥 feat: add Req and Res interfaces

Split the existing Ctx API into two separate APIs for Requests and
Responses. There are two goals to this change:

1. Reduce cognitive load by making it more obvious whether a Ctx method
   interacts with the request or the response.
2. Increase API parity with Express.

* fix(req,res): several issues

* Sprinkle in calls to Req() and Res() to a few unit tests
* Fix improper initialization caught by ^
* Add a few missing methods

* docs: organize Ctx methods by request and response

* feat(req,res): sync more missed methods

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-03-05 08:01:43 +01:00
Giovanni Rivera b568915b70
📚 docs: Add Retry Addon documentation (#3330)
* 📚 Doc: Add addon tab to /docs

* 📚 Doc: Add retry to addon docs

* 📚 Doc: Update retry README.md

* 🎨 Styles: Update addon/retry docs to respect markdownlint-cli2

* 📚 Doc: Update addon tab description to be singular

* 📚 Doc: Use retry prefix in retry docs

* 📚 Doc: Add retry addon to whats_new.md

* 🎨 Styles: Update whats_new.md to respect markdownlint-cli2
2025-02-27 08:46:41 +01:00
M. Efe Çetin bc4c920ea6
bind: add support for multipart file binding (#3309)
* deps: update schema to v1.3.0

* bind: add support for multipart file binding

* bind: fix linter

* improve coverage

* fix linter

* add test cases

---------

Co-authored-by: René <rene@gofiber.io>
2025-02-25 19:45:19 +01:00
RW a7bf8171b1
🐛 bug: Fix handler order in routing (#3321)
* fix handler order in routing
#3312

* fix handler order in routing
#3312

* fix handler order in routing
#3312

* fix handler order in routing
#3312

* fix handler order in routing
#3312

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-02-24 08:14:19 +01:00
JIeJaitt 4b62d3d592
🔥 feat: Improve and Optimize ShutdownWithContext Func (#3162)
* feat: Optimize ShutdownWithContext method in app.go

- Reorder mutex lock acquisition to the start of the function
- Early return if server is not running
- Use defer for executing shutdown hooks
- Simplify nil check for hooks
- Remove TODO comment

This commit improves the readability, robustness, and execution order
of the shutdown process. It ensures consistent state throughout the
shutdown and guarantees hook execution even in error cases.

* feat: Enhance ShutdownWithContext test for improved reliability

- Add shutdown hook verification
- Implement better synchronization with channels
- Improve error handling and assertions
- Adjust timeouts for more consistent results
- Add server state check after shutdown attempt
- Include comments explaining expected behavior

This commit improves the comprehensiveness and reliability of the
ShutdownWithContext test, ensuring proper verification of shutdown
hooks, timeout behavior, and server state during long-running requests.

* 📚 Doc: update the docs to explain shutdown & hook execution order

* 🩹 Fix: Possible Data Race on shutdownHookCalled Variable

* 🩹 Fix: Remove the default Case

* 🩹 Fix: Import sync/atomic

* 🩹 Fix: golangci-lint problem

* 🎨 Style: add block in api.md

* 🩹 Fix: go mod tidy

* feat: Optimize ShutdownWithContext method in app.go

- Reorder mutex lock acquisition to the start of the function
- Early return if server is not running
- Use defer for executing shutdown hooks
- Simplify nil check for hooks
- Remove TODO comment

This commit improves the readability, robustness, and execution order
of the shutdown process. It ensures consistent state throughout the
shutdown and guarantees hook execution even in error cases.

* feat: Enhance ShutdownWithContext test for improved reliability

- Add shutdown hook verification
- Implement better synchronization with channels
- Improve error handling and assertions
- Adjust timeouts for more consistent results
- Add server state check after shutdown attempt
- Include comments explaining expected behavior

This commit improves the comprehensiveness and reliability of the
ShutdownWithContext test, ensuring proper verification of shutdown
hooks, timeout behavior, and server state during long-running requests.

* 📚 Doc: update the docs to explain shutdown & hook execution order

* 🩹 Fix: Possible Data Race on shutdownHookCalled Variable

* 🩹 Fix: Remove the default Case

* 🩹 Fix: Import sync/atomic

* 🩹 Fix: golangci-lint problem

* 🎨 Style: add block in api.md

* 🩹 Fix: go mod tidy

* ♻️ Refactor: replaced OnShutdown  by OnPreShutdown and OnPostShutdown

* ♻️ Refactor: streamline post-shutdown hook execution in graceful shutdown process

* 🚨 Test: add test for gracefulShutdown

* 🔥 Feature: Using executeOnPreShutdownHooks and executeOnPostShutdownHooks Instead of OnShutdownSuccess and OnShutdownError

* 🩹 Fix: deal Listener err

* 🩹 Fix: go lint error

* 🩹 Fix: reduced memory alignment

* 🩹 Fix: reduced memory alignment

* 🩹 Fix: context should be created inside the concatenation.

* 📚 Doc: update what_new.md and hooks.md

* ♻️ Refactor: use blocking channel instead of time.Sleep

* 🩹 Fix: Improve synchronization in error propagation test.

* 🩹 Fix: Replace sleep with proper synchronization.

* 🩹 Fix: Server but not shut down properly

* 🩹 Fix: Using channels to synchronize and pass results

* 🩹 Fix: timeout with long running request

* 📚 Doc: remove OnShutdownError and OnShutdownSuccess from fiber.md

* Update hooks.md

* 🚨 Test: Add graceful shutdown timeout error test case

* 📝 Doc: Restructure hooks documentation for OnPreShutdown and OnPostShutdown

* 📝 Doc: Remove extra whitespace in hooks documentation

---------

Co-authored-by: yingjie.huang <yingjie.huang@fosunhn.net>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-02-22 17:32:51 +01:00
René d655e08a48 add more adpater documenation 2025-02-20 13:52:23 +01:00
René cdb862add1 add more adpater documenation 2025-02-20 12:58:08 +01:00
Lars Schumann 6148c6fe29
📚 Doc: Update intro.md Static Files section (#3303)
Update intro.md Static Files section

In v3 the apps Static method has been removed and its functionality has been moved to the static middleware.
The given code example has been updated accordingly.
2025-02-10 08:35:56 +01:00
René 7af9c93f5b add internal architecture docs 2025-02-04 09:17:43 +01:00
René d0ed605194 fix docs sync bug 2025-01-29 08:30:11 +01:00
René 4c09b32d14 fix docs for URI Binder 2025-01-29 08:16:03 +01: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
Juan Calderon-Perez 927e3b3266
Update whats_new.md 2025-01-19 02:38:34 -05:00
Giovanni Rivera 1dedc8034c
📚 Docs: Add `c.Drop()` example to `whats_new.md`
- Add Drop section with an example in `whats_new.md`
- Reorder `c.Drop()` and `c.End()` to match source code order
  in `whats_new.md`
2025-01-18 16:53:12 -08:00
aliziyacevik b31184e0b7 Doc: Added missing ctx.Drop() to whats_new.md 2025-01-18 14:31:55 +03:00
Giovanni Rivera a42ddc100e
🔥 feat: Add End() method to Ctx (#3280)
* 🔥 Feature(v3): Add End() method to Ctx

* 🎨 Style(Ctx): Respect linter in tests

* 🚨 Test(End): Add timeout test for c.End()

* 📚 Doc: Update End() documentation examples to use 4 spaces

* 🚨 Test: Update `c.End()` tests to use StatusOK

---------

Co-authored-by: Giovanni Rivera <grivera64@users.noreply.github.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2025-01-16 11:54:46 +01:00
René a95ffd8eff fix doc examples for generic function 2025-01-06 08:36:06 +01:00
Giovanni Rivera ac82b0c413
📚 Doc: Fix static middleware CacheDuration data type typo (#3273) 2025-01-03 10:36:58 +03:00
M. Efe Çetin 5355869d4d
🐛 bug: make Render bind parameter type any again (#3270)
* 🐛 bug: make Render bind parameter type any again

* update  docs
2025-01-02 08:42:25 +01:00
AuroraTea d0e767fc47
📚 Doc: Optimize the menu item text (#3267) 2024-12-31 15:58:07 +01:00
M. Efe Çetin 57744ebbe8
🐛 bug: fix EnableSplittingOnParsers is not functional (#3231)
* 🐛 bug: fix EnableSplittingOnParsers is not functional

* remove wrong testcase

* add support for external xml decoders

* improve test coverage

* fix linter

* update

* add reset methods

* improve test coverage

* merge Form and MultipartForm methods

* fix linter

* split reset and putting steps

* fix linter
2024-12-25 12:53:14 +01:00
ACHMAD IRIANTO EKA PUTRA 58677d5c86
feat: Add Drop method to DefaultCtx for silent connection termination (#3257)
* Add Drop method to DefaultCtx and remove redundant checks

Introduced a Drop method in DefaultCtx for closing connections, enabling easier resource management. Removed unnecessary nil-checks for headers in manager_msgp to simplify code logic. Added a unit test to ensure the new Drop method behaves as expected.

* Add `Drop` method to Fiber context API documentation

The `Drop` method allows silently terminating client connections without sending HTTP headers or a response body. This is useful for scenarios like mitigating DDoS attacks or blocking unauthorized access to sensitive endpoints. Example usage and function signature are included in the updated documentation.

* Remove extraneous blank line in documentation.

Eliminated an unnecessary blank line in the API context documentation for improved readability and formatting consistency. No functional changes were made to the content.

* Update API documentation example to return "Hello World!"

Revised the example code in the API documentation to return a generic "Hello World!" string instead of a dynamic response. This improves consistency and simplifies the example for easier understanding.

* Refactor Drop method and extend test coverage.

Simplified the Drop method by inlining the connection close call. Added new test cases to ensure proper handling of no-response scenarios and improved overall test coverage.

* fix golangci-lint issue

* Add test for Ctx.Drop with middleware interaction

This test ensures the correct behavior of the Ctx.Drop method when used with middleware, including response handling and error scenarios. It verifies that the middleware and handler properly handle the Drop call and its resulting effects.

* Add Drop method to DefaultCtx for closing connections

The Drop method allows closing connections without sending a response, improving control over connection handling. Also updated a test assertion to use StatusOK for improved readability and consistency.

* Refine Drop method comments to clarify error handling.

Explain the rationale for not wrapping errors in the Drop method. Emphasize that the returned error is solely for logging and not for further propagation or processing.

* Update Drop method documentation for clarity

Clarified the `Drop` method's behavior, specifying that it closes the connection without sending headers or a body. Added examples of use cases, such as DDoS mitigation and blocking sensitive endpoints.

* Refactor response header setting in middleware.

Replaced the direct header setting with the `Set` method for consistency and improved clarity. Removed a test case checking for a panic on closed response body as it is no longer applicable.
2024-12-23 08:20:41 +01:00
Kashiwa 69e5ccdd22
♻️ Refactor: Rename the Method Names of FormData and FormDatas (#3251) (#3255)
♻️ refactor: rename methods
2024-12-19 08:30:13 +01:00
Juan Calderon-Perez c2b557c5ac
🧹 chore: Update documentation for Fiber client (#3249)
* Update client package inline documentation

* Update inline docs

* Update Client Request docs

* Fix formatting issues

* Update docs

* Update docs/client/response.md

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

* Add missing space

* Remove return statement

* Update request.go

* Update docs/client/response.md

* Update docs/client/hooks.md

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: RW <rene@gofiber.io>
2024-12-16 14:25:15 +01:00
Iliya 154c74d578
🔥 feat: Add support for configuring TLS Min Version (#3248)
* Make tls.Config MinVersion configurable

This commit will resolve #3239
For more info: https://github.com/gofiber/fiber/issues/3239

* Add documents about tls minimum version configurable

* Add if statement for don't allow to use TLS1.0 and TLS1.1

* Fix lint issues, add test for panic()

* Update docs

* Add test with valid TLS version

---------

Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
2024-12-16 09:07:41 +01:00
M. Efe Çetin e9849b758d
🔥 feat: Add support for iterator methods to Fiber client (#3228)
* chore: simplify parserRequestBodyFile logic

* client: add support for go1.23 iterators

* Apply suggestions from code review

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

* fix linter

* fix tests

* correct benchmark

* fix linter

* create docs

* update

* rename FormDatas -> AllFormData

* add examples for maps.Collect()

* change request/response markdown examples

---------

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: René <rene@gofiber.io>
2024-12-10 10:39:23 +01:00
Jinquan Wang 27cfd3c8cd
🔥 feat: Add support for AutoTLS / ACME (#3201)
* feat: add a simple support for app.Listen

* fix: fix the nil access error

* chore: add test case for simple tls

* fix: align the struct

* chore: change the test case

can't passed and not chack the file yet

* fix: use TLS1.2 min

* Fix lint issues

* Fix call to os.MkdirTemp

* Fix test check order

* Update unit-tests for ACME

* Update docs

* Fix identation of whats_new examples

* More updates to docs

* Remove ACME tests. Add check for tlsConfig

* Add ACME section to whats_new docs

* Update docs/whats_new.md

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

* Update fiber.md

* Update whats_new.md

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-12-10 10:12:33 +01:00
Kashiwa 89a0cd3fa5
🔥 feat: Add support for graceful shutdown timeout in ListenConfig (#3220)
* 🔥 feat: Add support for graceful shutdown timeout in Listen

* 📚 doc: update the description of GracefulShutdownTimeout

* ♻️refact: use require.ErrorIs instead of require.Equal

* fix: Target error should be in err chain by using fasthttputil.ErrInmemoryListenerClosed

* ♻️refact: use require.ErrorIs instead of require.Equal

* 📚doc: update the description of GracefulShutdownTimeout

* ♻️refact: rename GracefulShutdownTimeout to ShutdownTimeout

* 🩹fix: set default ShutdownTimeout to 10s

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-12-04 13:55:36 +01:00
M. Efe Çetin 77622700d7
chore: mark go1.23 as minimum go version (#3226) 2024-12-01 14:39:49 +01:00
Hao Chun Chang 67021360e1
🔥 Feature: Add AllLogger to Config (#3153)
* 🔥 Feature: Add SetFlags to Logger Interface

🔥 Feature: Add fiberlog Logger field to config

* 🚨 Test: custom-defined Logger and LoggerFunc

* 📚 Doc: add LoggerFunc and Logger to middleware logger

* 🚨 Test: fine-tune custom Logger and LoggerFunc

* 📚 Doc: add Logger documentation

📚 Doc: add custom Logger example

* 🩹 fix: add default Logger field to default config

* 📚 Doc: remove Logger field in middleware logger

📚 Doc: add example of using fiber logger interface

* 🚨 Test: add tests for using fiber logger interface wrapper

* 📚 Doc: update custom logger example

* Update docs/middleware/logger.md

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

* update

* update logger docs

* update what's new

* replace setflags with getloggerinstance

* fix linter

* update

* Fix markdownlint issues

* apply reviews & improve coverage

* fix linter

* rename controllogger

* Update whats_new.md

expandable example

---------

Co-authored-by: RW <rene@gofiber.io>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Muhammed Efe Cetin <efectn@protonmail.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-12-01 13:32:52 +01:00
René f31ec351c7 Update constants.md documentation 2024-12-01 13:17:38 +01:00
RW 60dfd6b313
Update constants.md
fix syntax
2024-12-01 13:04:14 +01:00
Sumit Kumar 26cc477500
🔥 feat: Add support for CBOR encoding (#3173)
* feat(cbor): allow encoding response bodies in cbor

* fix(tests::cbor): encode struct instead of a randomly ordered hashmap

* docs(whats_new): add cbor in context section

* feat(binder): introduce CBOR

* feat(client): allow cbor in fiber client

* chore(tests): add more test

* chore(packages): go mod tidy

* fix(binder): update CBOR name and test

* improve test coverage

* improve test coverage

* update1

* add docs

* doc fixes

* update

* Fix markdown lint

* Add missing entry from binder README

* add/refresh documentation

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: M. Efe Çetin <efectn@protonmail.com>
Co-authored-by: RW <rene@gofiber.io>
2024-12-01 11:03:50 +01:00
René 89452fea32 Update whats_new.md documentation 2024-11-29 16:12:15 +01:00
René 86fd29ac27 Update whats_new.md documentation 2024-11-29 16:04:10 +01:00
René 6a36f6d4e6 Update whats_new.md documentation 2024-11-29 15:56:31 +01:00
Giovanni Rivera 31a503f699
🔥 Feature (v3): Add buffered streaming support (#3131)
* 🔥 Feature: Add SendStreamWriter to Ctx

Create a new `*DefaultCtx` method called `SendStreamWriter()`
that maps to fasthttp's `Response.SetBodyStreamWriter()`

* 🚨 Test: Validate regular use of c.SendStreamWriter()

- Adds Test_Ctx_SendStreamWriter to ctx_test.go

* 🚨 Test: (WIP) Validate interrupted use of c.SendStreamWriter()

- Adds Test_Ctx_SendStreamWriter_Interrupted to ctx_test.go
    - (Work-In-Progress) This test verifies that some data is
      still sent before a client disconnects when using the method
      `c.SendStreamWriter()`.

**Note:** Running this test reports a race condition when using
the `-race` flag or running `make test`. The test uses a channel
and mutex to prevent race conditions, but still triggers a warning.

* 📚 Doc: Add `SendStreamWriter` to docs/api/ctx.md

* 🩹 Fix: Remove race condition in Test_Ctx_SendStreamWriter_Interrupted

* 🎨 Styles: Update ctx_test.go to respect golangci-lint

* 📚 Doc: Update /docs/api/ctx.md to show proper `w.Flush()` error handling

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

* 🎨 Styles: Update /docs/whats_new.md to respect markdownlint-cli2

* 🩹 Fix: Fix Fprintf syntax error in docs/whats_new.md

---------

Co-authored-by: M. Efe Çetin <efectn@protonmail.com>
2024-11-27 11:11:56 +01:00
Mitul Agrawal 359343625b
🔥 feat: Add support for creating Fiber client from existing FastHTTP client (#3214)
* add support to create client from existing client

* add NewWithClient to documentation

* fix typo in comment

* fix and shorten comment

* add unit test for NewWithClient

* add nil check and test

* fix lint check
2024-11-25 11:54:07 +01:00
ItsMeSamey f08ebf4335
🐛 fix: Nil pointer dereference with Must Bind binding (#3171)
* Fix nil pointer dereference with Must Bind binding error

if err is nil err.Error() panics
(eg. c.Bind().Must().JSON(...) successfully binds but panics

* Added returnErr test

make sure returnErr works with nil error

* Reordered returnErr nil check

as in majority of cases we expect err to be nil, this should provide better short-cutting

* Use require.NoError

* Update bind_test.go

* Renamed Must to WithAutoHandling

* Update bind.md

Added a requested clarification

* renamed Should to WithoutAutoHandling and Bind.should to Bind.dontHandle

* renamed dontHandle to dontHandleErrs

* fixed formatting

* fixed a typo

* Update binder documentation

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-11-25 11:51:36 +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 ba83a6e1ce
📚 Doc: Updates to Context documentation (#3206)
* Update context documentation

* Update docs/api/ctx.md

---------

Co-authored-by: RW <rene@gofiber.io>
2024-11-18 10:10:59 +01:00
Juan Calderon-Perez a12ca10cac
📚 Doc: Updates to API documentation and README (#3205)
* Updates to documentation

* Update .github/README.md

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

* Remove trailing spaces

* Updates based on PR comments

* Update docs/api/bind.md

* Update docs/api/redirect.md

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: RW <rene@gofiber.io>
2024-11-16 15:24:14 +01:00
JIeJaitt f725ded92b
🔥 feat: Add Context Support to RequestID Middleware (#3200)
* Rename UserContext() to Context(). Rename Context() to RequestCtx()

* feat: add requestID in UserContext

* Update Ctxt docs and What's new

* Remove extra blank lines

* ♻️ Refactor: merge issue #3186

* 🔥 Feature: improve FromContext func and test

* 📚 Doc: improve requestid middleware

* ♻️ Refactor: Rename interface to any

* fix: Modify structure sorting to reduce memory usage

---------

Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-11-15 17:34:20 +01:00
Juan Calderon-Perez 16f9056f5f
🐛 fix: Improve naming convention for Context returning functions (#3193)
* Rename UserContext() to Context(). Rename Context() to RequestCtx()

* Update Ctxt docs and What's new

* Remove extra blank lines

---------

Co-authored-by: M. Efe Çetin <efectn@protonmail.com>
2024-11-13 16:12:19 +01:00
Juan Calderon-Perez 7cddb84b21
📚 Doc: Update intro documentation (#3204)
Auto update intro documentation
2024-11-13 13:11:09 +01:00
xEricL 579d9a3f3d
📚 Doc: Clarify SendFile Docs (#3172)
* 📚 Doc: Clarify SendFile ContentType header set by file format

* 📚 Doc: Make SendFile default value formatting consistent

* 📚 Doc: Add missing `fiber.` in SendFile usage docs

* 📚 Doc: Hyphenate 'case-sensitive'

* 📚 Doc: Clarify `SendFile` behavior for missing/invalid file extensions

* 🚨 Test: Validate `SendFile` Content-Type header

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-10-28 08:11:24 +01:00