websocket
websocket copied to clipboard
How to get Request Headers in websocket context
Hi @surjit am not sure why you wanna put the headers in the context but you can use c.locals(key,value)
to send the headers from the http request using a middleware before the upgrade.
here's an example
func SocketMiddleware(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
token := c.GetReqHeaders()["Authorization"]
c.Locals("token", token)
return c.Next()
}
return fiber.ErrUpgradeRequired
}