-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Problem with CORS and websockets #11
Comments
@majidbigdeli I know that you are using websockets+cors middleware, so I have to ask you too, do you have the same issue with cors on websockets? |
@kataras I have not issue with cors . |
@xXLokerXx please change |
it issue related to DefaultGorillaUpgrader in my test . |
@xXLokerXx @majidbigdeli There is no issue with neffos at all, you don't need to delete a header or things like that, this happesn only on Gorilla websocket upgrader because it has a CheckOrigin field which by-default allows only same-origin. So the solution is to modify that to allow everything - you don't need to catch anything there - neffos + cors will do the job. The gorilla websocket's check origin is type of: func (r *http.Request) bool Example Code: import "github.com/kataras/neffos"
import "github.com/kataras/neffos/gorilla"
import gorillaWs "github.com/gorilla/websocket"
// [...]
websocketServer := websocket.New(
gorilla.Upgrader(gorillaWs.Upgrader{CheckOrigin: func(*http.Request) bool{return true}}),
serverEvents) Hope that helped! |
@kataras yes . Gorilla websocket upgrader has a CheckOrigin field . Thank you. |
Yes, that help me a lot, i'll implement right now |
You are welcome @xXLokerXx of course! |
it works.
it works. |
Describe the bug
I have an issue with cors, when i run it the example in 2 diferents ports (3000, 3001) and i try to conect a new socket from 3001 to 3000 then the console throw the next error:
WebSocket connection to 'ws://localhost:3001/echo?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU' failed: Error during WebSocket handshake: Unexpected response code: 403
.To Reproduce
Use the example server.go on the route:
_examples/websocket/basic/
Expected behavior
I would like to make petitions from the 2 servers
Posible fix
To catch this i made a middleware function wich delete the origin header (but this will be a rellay bad practice), code above:
The text was updated successfully, but these errors were encountered: