diff --git a/transport/internet/ws/config_json.go b/transport/internet/ws/config_json.go index 843e549b1..dbb04cd54 100644 --- a/transport/internet/ws/config_json.go +++ b/transport/internet/ws/config_json.go @@ -9,6 +9,8 @@ func (this *Config) UnmarshalJSON(data []byte) error { ConnectionReuse bool `json:"connectionReuse"` Path string `json:"Path"` Pto string `json:"Pto"` + Cert string `json:"Cert"` + PrivKey string `json:"PrivKet"` } jsonConfig := &JsonConfig{ ConnectionReuse: true, @@ -21,5 +23,7 @@ func (this *Config) UnmarshalJSON(data []byte) error { this.ConnectionReuse = jsonConfig.ConnectionReuse this.Path = jsonConfig.Path this.Pto = jsonConfig.Pto + this.PrivKey = jsonConfig.PrivKey + this.Cert = jsonConfig.Cert return nil } diff --git a/transport/internet/ws/hub.go b/transport/internet/ws/hub.go index cc4563c20..412fb8950 100644 --- a/transport/internet/ws/hub.go +++ b/transport/internet/ws/hub.go @@ -69,8 +69,18 @@ func (wsl *WSListener) listenws(address v2net.Address, port v2net.Port) error { errchan := make(chan error) + listenerfunc := func() error { + return http.ListenAndServe(address.String()+":"+strconv.Itoa(int(port.Value())), nil) + } + + if effectiveConfig.Pto == "wss" { + listenerfunc = func() error { + return http.ListenAndServeTLS(address.String()+":"+strconv.Itoa(int(port.Value())), effectiveConfig.Cert, effectiveConfig.PrivKey, nil) + } + } + go func() { - err := http.ListenAndServe(address.String()+":"+strconv.Itoa(int(port.Value())), nil) + err := listenerfunc() errchan <- err return }()