-
-
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
🤗 [Question]: Enable DisableHeaderNormalizing config will occur wrong cors middleware behaviour #2985
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 |
@Max-Cheng Which version of v2 are you running? |
The main issue is whether Enable DisableHeaderNormalizing should affect the behavior of the CORS middleware or not. |
Ping @sixcolors |
|
In my situation, I'm using a global middleware to enforce the Origin header to be in uppercase and process the correct logical path. package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
app := fiber.New(fiber.Config{
DisableHeaderNormalizing: true,
})
app.Use(func(c *fiber.Ctx) error {
if c.Get("origin") != "" {
c.Request().Header.Set(fiber.HeaderOrigin, c.Get("origin"))
return c.Next()
}
return c.Next()
})
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowMethods: "*",
AllowHeaders: "*",
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
log.Fatal(app.Listen(":3000"))
} |
This should not be the case. CORS middleware calls I will test and get back to you. |
@Max-Cheng I understand what you mean now. If you set Since the Cross-Origin Resource Sharing (CORS) and other middleware included with fiber use However, the comment for // When set to true, disables header normalization.
// By default all header names are normalized: conteNT-tYPE -> Content-Type.
//
// Default: false Because https://docs.gofiber.io/api/ctx/#get notes that: "The match is case-insensitive." and the |
It appears that the only effect that The fasthttp documentation for this setting is a bit more detailed on its effects: // Header names are passed as-is without normalization
// if this option is set.
//
// Disabled header names' normalization may be useful only for proxying
// incoming requests to other servers expecting case-sensitive
// header names. See https://github.com/valyala/fasthttp/issues/57
// for details.
//
// By default request and response header names are normalized, i.e.
// The first letter and the first letters following dashes
// are uppercased, while all the other letters are lowercased.
// Examples:
//
// * HOST -> Host
// * content-type -> Content-Type
// * cONTENT-lenGTH -> Content-Length
DisableHeaderNamesNormalizing bool |
Yes. I don't think we should change the behaviour of the CORS middleware |
Another mistake in this case. https://github.com/gofiber/fiber/blob/v2/middleware/cors/cors.go#L177 |
Question Description
About
fiber.Config{DisableHeaderNormalizing:true}
and using cors middleware will occur client sendorigin: hostxxx
will not return CORS header.Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: