websocket icon indicating copy to clipboard operation
websocket copied to clipboard

WSS support

Open VinnieCool opened this issue 1 year ago • 3 comments

Is there an existing feature request for this?

  • [X] I have searched the existing feature requests

Is your feature request related to a problem? Please describe.

AWS allows only wss and not ws. WSS is not just secure, it is better because the ISPs and gateways won't block wss traffic as they don't see it

Describe the solution that you would like.

Provide wss support in gorilla-websocket implementation, or guide/point me so I can help add

Describe alternatives you have considered.

No response

Anything else?

No response

VinnieCool avatar Aug 05 '23 20:08 VinnieCool

The package supports WSS clients and servers.

To dial a connection using WSS, specify "wss" as the URL scheme. Search for "wss" in client.go to find the relevant code.

To handle WSS connections on the server, register your websocket endpoint with an HTTP server listening for HTTPS connections. There is no code in the repository specific to serving WSS connections because TLS is handled by the HTTP server.

ghost avatar Aug 05 '23 23:08 ghost

Changes to echo example for using TLS.

Set TLS port (and use all interfaces if wanted).

var addr = flag.String("addr", ":443", "https service address")

Use wss.

homeTemplate.Execute(w, "wss://"+r.Host+"/echo")

Serve TLS with certificate and key.

log.Fatal(http.ListenAndServeTLS(*addr, "server.crt", "server.key", nil))

Generate certificates for testing. openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365

Cloudflare example for production. Add a proxied DNS record for the domain. Create the certificate and key for it under SSL/TLS -> Origin Server.

flower7434 avatar Mar 19 '24 12:03 flower7434

@VinnieCool As noted in a previous comment, the websocket package supports the WSS protocol on the client and server. Please describe the problem you encountered in more detail.

ghost avatar Jun 15 '24 02:06 ghost