Reputation: 21985
I get this error when I try to connect to my websocket server:
Error during WebSocket handshake: origin mismatch: http://skerit.com != http://kipdola.be
Sure enough, I had to put in an origin response, like this:
self.client.send("Sec-WebSocket-Origin: http://kipdola.be\r\n")
self.client.send("Sec-WebSocket-Location: ws://kipdola.be:1234/\r\n")
But how do I set it to allow multiple origins?
Upvotes: 0
Views: 624
Reputation: 421
You just echo back the origin the user provided in the request, the request looks somewhat like this:
GET / HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: skerit.com
Origin: http://skerit.com
You perform a serverside check if the Origin
header is in your list of allowed origins and just echo the origin back to the client:
self.client.send("Sec-WebSocket-Origin: " + headers["Origin"] + "\r\n")
Upvotes: 1