From 4c818d28cce8758a6fd566cabee209bbe4a629c9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Mar 2023 18:33:55 +0100 Subject: [PATCH] Add https:// and http+insecure:// listeners Same as wss:// and ws+insecure://, except we'll be able to add more endpoints for future features (e.g. file uploads). --- cmd/soju/main.go | 35 +++++++++++++++++++++++++++++++++++ doc/soju.1.scd | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/cmd/soju/main.go b/cmd/soju/main.go index 5c34460..114b038 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -145,6 +145,9 @@ func main() { srv.SetConfig(serverCfg) srv.Logger = soju.NewLogger(log.Writer(), debug) + httpMux := http.NewServeMux() + httpMux.Handle("/socket", srv) + for _, listen := range cfg.Listen { listen := listen // copy listenURI := listen @@ -332,6 +335,38 @@ func main() { log.Fatalf("serving %q: %v", listen, err) } }() + case "https": + if tlsCfg == nil { + log.Fatalf("failed to listen on %q: missing TLS configuration", listen) + } + addr := u.Host + if _, _, err := net.SplitHostPort(addr); err != nil { + addr = addr + ":https" + } + httpSrv := http.Server{ + Addr: addr, + TLSConfig: tlsCfg, + Handler: httpMux, + } + go func() { + if err := httpSrv.ListenAndServeTLS("", ""); err != nil { + log.Fatalf("serving %q: %v", listen, err) + } + }() + case "http+insecure": + addr := u.Host + if _, _, err := net.SplitHostPort(addr); err != nil { + addr = addr + ":http" + } + httpSrv := http.Server{ + Addr: addr, + Handler: httpMux, + } + go func() { + if err := httpSrv.ListenAndServe(); err != nil { + log.Fatalf("serving %q: %v", listen, err) + } + }() default: log.Fatalf("failed to listen on %q: unsupported scheme", listen) } diff --git a/doc/soju.1.scd b/doc/soju.1.scd index e8f45dd..eea3436 100644 --- a/doc/soju.1.scd +++ b/doc/soju.1.scd @@ -88,6 +88,10 @@ The following directives are supported: - _irc+insecure://[host][:port]_ listens with plain-text over TCP (default port if omitted: 6667) - _unix://_ listens on a Unix domain socket + - _https://[host][:port]_ listens for HTTPS connections (default port: 443) + and handles WebSocket requests at endpoint _/socket_ + - _http+insecure://[host][:port]_ listens for plain-text HTTP connections + (default port: 80) and handles WebSocket requests at endpoint _/socket_ - _wss://[host][:port]_ listens for WebSocket connections over TLS (default port: 443) - _ws+insecure://[host][:port]_ listens for plain-text WebSocket