Skip to content

Commit 0673cf7

Browse files
committed
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.
1 parent f08cd15 commit 0673cf7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/api/ctx.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,28 @@ app.Get("/", func(c fiber.Ctx) error {
463463
})
464464
```
465465

466+
## Drop
467+
468+
Terminates the client connection silently without sending any HTTP headers or response body.
469+
470+
This can be used for scenarios where you want to block certain requests without notifying the client, such as mitigating
471+
DDoS attacks or protecting sensitive endpoints from unauthorized access.
472+
473+
```go title="Signature"
474+
func (c fiber.Ctx) Drop() error
475+
```
476+
477+
```go title="Example"
478+
app.Get("/", func(c fiber.Ctx) error {
479+
if c.IP() == "192.168.1.1" {
480+
return c.Drop()
481+
}
482+
483+
return c.SendString("Hello, " + name)
484+
})
485+
```
486+
487+
466488
## Format
467489

468490
Performs content-negotiation on the [Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) HTTP header. It uses [Accepts](ctx.md#accepts) to select a proper format from the supplied offers. A default handler can be provided by setting the `MediaType` to `"default"`. If no offers match and no default is provided, a 406 (Not Acceptable) response is sent. The Content-Type is automatically set when a handler is selected.

0 commit comments

Comments
 (0)