Changeset 323 in code for trunk/cmd


Ignore:
Timestamp:
Jun 7, 2020, 12:13:46 PM (5 years ago)
Author:
contact
Message:

Add support for WebSocket connections

WebSocket connections allow web-based clients to connect to IRC. This
commit implements the WebSocket sub-protocol as specified by the pending
IRCv3 proposal [1].

WebSocket listeners can now be set up via a "wss" protocol in the
listen directive. The new http-origin directive allows the CORS
allowed origins to be configured.

[1]: https://github.com/ircv3/ircv3-specifications/pull/342

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/soju/main.go

    r317 r323  
    66        "log"
    77        "net"
     8        "net/http"
    89        "net/url"
    910        "strings"
     
    5758        srv.Hostname = cfg.Hostname
    5859        srv.LogPath = cfg.LogPath
     60        srv.HTTPOrigins = cfg.HTTPOrigins
    5961        srv.Debug = debug
    6062
     
    98100                                log.Fatal(srv.Serve(ln))
    99101                        }()
     102                case "wss":
     103                        addr := u.Host
     104                        if _, _, err := net.SplitHostPort(addr); err != nil {
     105                                addr = addr + ":https"
     106                        }
     107                        httpSrv := http.Server{
     108                                Addr:      addr,
     109                                TLSConfig: tlsCfg,
     110                                Handler:   srv,
     111                        }
     112                        go func() {
     113                                log.Fatal(httpSrv.ListenAndServeTLS("", ""))
     114                        }()
     115                case "ws+insecure":
     116                        addr := u.Host
     117                        if _, _, err := net.SplitHostPort(addr); err != nil {
     118                                addr = addr + ":http"
     119                        }
     120                        httpSrv := http.Server{
     121                                Addr:    addr,
     122                                Handler: srv,
     123                        }
     124                        go func() {
     125                                log.Fatal(httpSrv.ListenAndServe())
     126                        }()
    100127                default:
    101128                        log.Fatalf("failed to listen on %q: unsupported scheme", listen)
Note: See TracChangeset for help on using the changeset viewer.