diff options
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -2,6 +2,7 @@ package goxy import ( "crypto/tls" + "net" "net/http" "net/http/httputil" "net/url" @@ -10,6 +11,7 @@ import ( type Server struct { DataFile string Routes + SNI wwwServer http.Server tlsServer http.Server rpcServer http.Server @@ -22,6 +24,7 @@ func NewServer(dataFile, listenWWW, listenTLS, listenRPC string) (*Server, error server := &Server{ DataFile: dataFile, Routes: make(Routes), + SNI: make(SNI), wwwServer: http.Server{Addr: listenWWW}, tlsServer: http.Server{Addr: listenTLS}, rpcServer: http.Server{Addr: listenRPC}, @@ -60,13 +63,16 @@ func (s *Server) UpdateMux() error { return err } - if r.certificate == nil && serverName.Scheme == "https" { + if serverName.Scheme == "https" { cert, err := tls.X509KeyPair(r.Cert, r.Key) if err != nil { return err } - r.certificate = &cert - s.Routes[host] = r + slug, _, err := net.SplitHostPort(serverName.Host) + if err != nil { + slug = serverName.Host + } + s.SNI[slug] = &cert } switch serverName.Scheme { |