rampatowl
rampatowl

Reputation: 1772

AWS websocket server: 403 error when connecting from browser, fine from Python

I deployed a websocket server on an AWS EC2 instance. I am able to connect to this websocket without any issues from a Python script (using websocket.create_connection), but I get a 403 error when running the Javascript line var ws = new Websocket(.....) in Chrome: Error during WebSocket handshake: Unexpected response code: 403.

I made sure to change the security group on the EC2 instance to allow all inbound and outbound traffic.

All suggestions appreciated!

EDIT: Figured out what was going on here. It was an issue with the default origin check function in my Go websocket server.

Upvotes: 0

Views: 938

Answers (1)

rampatowl
rampatowl

Reputation: 1772

This was a server-side issue with the gorilla/websocket package. Had to add this CheckOrigin function:

var upgrader = websocket.Upgrader{
    ReadBufferSize: 1024,
    WriteBufferSize: 1024,
    CheckOrigin: func(r *http.Request) bool {return true},
}

Upvotes: 1

Related Questions