diff options
| author | tjpcc <tjp@ctrl-c.club> | 2023-10-31 08:16:11 -0600 |
|---|---|---|
| committer | tjpcc <tjp@ctrl-c.club> | 2023-10-31 08:22:51 -0600 |
| commit | 9d102cb910fe9687b94235da04125329cd787054 (patch) | |
| tree | dd3bde6932a3b59e529725b5bddf7f795eacfc1b /gemini.go | |
| parent | 9a20e4b1da629a3ce1fc217304acd1a2a394341a (diff) | |
use MultiTLS to support separate TLS configs when virtualhosting gemini
fixes #10
Diffstat (limited to 'gemini.go')
| -rw-r--r-- | gemini.go | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -3,7 +3,6 @@ package main import ( "context" "crypto/tls" - "errors" "fmt" "strings" @@ -58,23 +57,18 @@ func buildGeminiServers(servers []Server, config *Configuration) ([]sr.Server, e } } - var tlsConfig *tls.Config - var keyfile, certfile string + tlsConfigs := map[string]*tls.Config{} + var fallback *tls.Config = nil for _, config := range configs { - if (keyfile != "" && config.tlsKeyFile == keyfile) || (certfile != "" && config.tlsCertFile == certfile) { - return nil, errors.New("conflicting 'servertls' directives for gemini server") - } - - if config.TLS != nil { - tlsConfig = config.TLS - keyfile = config.tlsKeyFile - certfile = config.tlsCertFile - break + if len(config.Hostnames) > 0 && config.TLS != nil { + for _, hostname := range config.Hostnames { + tlsConfigs[hostname] = config.TLS + } + } else { + fallback = config.TLS } } - if tlsConfig == nil { - return nil, errors.New("gemini server must have a servertls directive") - } + tlsConfig := gemini.MultiTLS(tlsConfigs, fallback) gemsrv, err := gemini.NewServer( context.Background(), |
