You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue description
When setting Status in conjunction with SendFile in a middleware function, in my case, the last handler for a catchall for nonexistent routes, the status is not being set, but instead defaulting to 200 which is default for SendFile. This is slightly different behavior from what is expected based on a different example from the docs. The html is SendFile is correct, but the status code is not.
Expected behavior
The response should contain the set status code. On the attached code snippet, the response code should be 404.
Steps to reproduce
Output using httpie
>> http -p h :3001/nonexistant
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 1025
Content-Type: text/html; charset=utf-8
Date: Sun, 17 May 2020 21:42:30 GMT
Last-Modified: Tue, 12 May 2020 20:40:50 GMT
Code snippet
package main
import"github.com/gofiber/fiber"funcmain() {
app:=fiber.New()
// .. all other middlewares// .. all routes// last handler before port// catchall 404app.Use(func(c*fiber.Ctx) {
c.Status(404).SendFile("./pages/404.html")
})
app.Listen(port)
}
The text was updated successfully, but these errors were encountered:
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
Welcome @securisec, thank you for your detailed bug report!
I reproduced the same result using SendFile(), this is because Fasthttp overwrites the status code. I applied a fix and this will ship with the next release in v1.10.
For the time being, you could use the following snippet:
Fiber version/commit
1.9.6
Issue description
When setting
Status
in conjunction withSendFile
in a middleware function, in my case, the last handler for a catchall for nonexistent routes, the status is not being set, but instead defaulting to 200 which is default forSendFile
. This is slightly different behavior from what is expected based on a different example from the docs. The html isSendFile
is correct, but the status code is not.Expected behavior
The response should contain the set status code. On the attached code snippet, the response code should be 404.
Steps to reproduce
Output using httpie
Code snippet
The text was updated successfully, but these errors were encountered: