gofiber / fiber

⚡️ Express inspired web framework written in Go
https://gofiber.io
MIT License
34.13k stars 1.68k forks source link

🚀 [Feature]: Add an "End" method to flush the response stream with an empty body #2582

Closed mattcarlotta closed 1 year ago

mattcarlotta commented 1 year ago

Feature Description

Since Fiber models itself to the Express API, it would be nice if Fiber provided an end method.

This would simplify the following code from...

func Example(c *fiber.Ctx) error {
    return c.Send(nil)
}

to:

func Example(c *fiber.Ctx) error {
    return c.End()
}

It would also be nice for it to be invokable at the end of a context chain:

func Example(c *fiber.Ctx) error {
    return c.Status(http.StatusOK).End()
}

Additional Context (optional)

While writing .Send(nil) over and over is not the end of the world, .End() would be a subjectively cleaner way to communicate an empty response body.

That said, calling .End() could simply be an alias for .Send(nil)

Code Snippet (optional)

No response

Checklist:

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

mattcarlotta commented 1 year ago

Closing this RFC as it doesn't appear to be possible with how fasthttp flushes the stream: click here for more info.