1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-06 13:49:31 +00:00

14 Commits

Author SHA1 Message Date
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
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
Juan Calderon-Perez
845a7f8b8e
🧹 chore: Improve Performance of Fiber Router (#3261)
* Initial improvements

* Update test

* Improve RemoveEscapeChar performance

* Fix lint issues

* Re-add comments

* Add dedicated request handlers

* Fix lint issues

* Add test case for app.All with custom method

* Add test for custom Ctx and Request Methods

* Simplify test logic

* Simplify test
2024-12-29 19:34:34 +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
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
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
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
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
xEricL
298975a982
🔥Feature: Add support for TrustProxy (#3170)
* 🔥 Feature: Add `TrustProxyConfig` and rename `EnableTrustedProxyCheck` to `TrustProxy`

* 📚 Doc: Document TrustProxyConfig usage and migration

* 🚨 Test: Validate and Benchmark use of TrustProxyConfig

* 🩹 Fix: typo in RequestMethods docstring

* 🩹 Fix: typos in TrustProxy docstring and JSON tags

* 🩹 Fix: Move `TrustProxyConfig.Loopback` to beginning of if-statement

* 🎨 Style: Cleanup spacing for Test_Ctx_IsProxyTrusted

* 📚 Doc: Replace `whitelist` with `allowlist` for clarity

* 📚 Doc: Improve `TrustProxy` doc wording

* 🩹 Fix: validate IP addresses in `App.handleTrustedProxy`

* 🩹 Fix: grammatical errors and capitalize "TLS"
2024-10-17 08:29:03 +02:00
Juan Calderon-Perez
f8c514cb25
v3: Optimize IsFromLocal() performance (#3140)
Optimize IsFromLocal()
2024-09-23 15:16:52 +02:00
M. Efe Çetin
08d9fda631
enhancement: use msgp for flash message encoding/decoding (#3099)
* enhancement: use msgp for flash message encoding/decoding

* add msgp tests

* improve test coverage

* improve test coverage

* fix linter

* update makefile

* extend go generation process

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: René <rene@gofiber.io>
2024-08-29 16:45:16 +02:00
M. Efe Çetin
21ede5954c
v3 (feature): add configuration support to c.SendFile() (#3017)
*  v3 (feature): add configuration support to c.SendFile()

* update

* cover more edge-cases

* optimize

* update compression, add mutex for sendfile slice

* fix data races

* add benchmark

* update docs

* update docs

* update

* update tests

* fix linter

* update

* update tests

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
2024-06-30 21:15:22 +02:00
Jason McNeil
011e83b390
docs: Improve ctx.Locals method description, godoc and example (#3032)
* docs: Improve ctx.Locals method description, godoc and example

* docs: Update ctx.md to use value receiver for fiber.Ctx in app.Use and app.Get

* chore: Update userKey type in ctx.md

* docs: Update ctx.md

* chore: Add description for Locals method in Ctx interface
2024-06-18 08:27:38 +02:00
RW
046b4a9d4e
Adding a generator to generate the CTX interface (#3024) 2024-06-03 08:37:22 +02:00