-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐞 app.Static serving index.html
as text/plain
#420
Comments
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 |
@soulchainer I couldn't produce the same result, by any chance you are using Windows? Because it could be caused by a specific windows update that changed the MIME types in the registry. @thomasvvugt do you remember how you solved this issue? To make sure it's OS related I added an additional test case #421 |
index.html
as text/plain 🐞 index.html
as text/plain
@Fenny No, I'm using Arch Linux. Fiber v1.10.1 |
Could you try to run this test app_test.go#L208 on your machine (there is an Could you also share the |
@Fenny That test runs OK, because it doesn't cover this case, but only the case where it already works. As I said, if you have If you edit that test adding the extra line that I add below, which covers this error case: func Test_App_Static_Index(t *testing.T) {
app := New()
// I added this line, some folder in your machine, obviosly this should be some other general file, quick check for my case
app.Static("/music", "/home/soulchainer/Music")
app.Static("/", "./.github")
req := httptest.NewRequest("GET", "/", nil)
resp, err := app.Test(req)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
utils.AssertEqual(t, false, resp.Header.Get("Content-Length") == "")
utils.AssertEqual(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, true, strings.Contains(string(body), "Hello, World!"))
} It fails like this: --- FAIL: Test_App_Static_Index (0.00s)
utils.go:169:
Test: Test_App_Static_Index
Trace: app_test.go:219
Error: Not equal
Expect: text/html; charset=utf-8 [string]
Result: text/plain; charset=utf-8 [string]
FAIL
FAIL github.com/gofiber/fiber 0.008s
FAIL Which is what I said is happening. My current
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cliente</title>
</head>
<body>
Hello world!
</body>
</html> |
Thank you for your detailed bug report, I will debug this today and keep you posted 👍 |
am also interested in this bug as I noticed the same behavior in one of our microservices, had debugged it before and was able to trace it back to fasthttp, where the default content type is used Take a closer look tomorrow |
The content-type issue has been fixed in v1.10.2 Thank you for your issue 👍 |
Using Fiber v1.10.1
Question description
I'm not sure if this is a bug or I understood it wrong.
It seems the root route must be defined first of all routes, otherwise its content will be rendered as plain text.
Code snippet (optional)
This will result in
index.html
, at/
, being rendered as text/plain:This will result in
index.html
, at/
, being rendered as text/html:Of course, this is not a big deal. It's customary to put the root first most of the time, but even so I just don't know, is this intended behavior or...?
Thanks for your time!
The text was updated successfully, but these errors were encountered: