Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

How to get Request Headers in websocket context #102

Open
surjit opened this issue Mar 9, 2022 · 1 comment
Open

How to get Request Headers in websocket context #102

surjit opened this issue Mar 9, 2022 · 1 comment
Labels
🤔 Question Further information is requested

Comments

@surjit
Copy link

surjit commented Mar 9, 2022

No description provided.

@ReneWerner87 ReneWerner87 added the 🤔 Question Further information is requested label Mar 9, 2022
@oSethoum
Copy link

oSethoum commented Mar 2, 2023

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
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants