1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00

Support Listen WebSocket with TLS

This commit is contained in:
Shelikhoo 2016-08-13 21:56:51 +08:00
parent fecf9cc5b8
commit 16b529093d
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21
2 changed files with 15 additions and 1 deletions

View File

@ -9,6 +9,8 @@ func (this *Config) UnmarshalJSON(data []byte) error {
ConnectionReuse bool `json:"connectionReuse"` ConnectionReuse bool `json:"connectionReuse"`
Path string `json:"Path"` Path string `json:"Path"`
Pto string `json:"Pto"` Pto string `json:"Pto"`
Cert string `json:"Cert"`
PrivKey string `json:"PrivKet"`
} }
jsonConfig := &JsonConfig{ jsonConfig := &JsonConfig{
ConnectionReuse: true, ConnectionReuse: true,
@ -21,5 +23,7 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.ConnectionReuse = jsonConfig.ConnectionReuse this.ConnectionReuse = jsonConfig.ConnectionReuse
this.Path = jsonConfig.Path this.Path = jsonConfig.Path
this.Pto = jsonConfig.Pto this.Pto = jsonConfig.Pto
this.PrivKey = jsonConfig.PrivKey
this.Cert = jsonConfig.Cert
return nil return nil
} }

View File

@ -69,8 +69,18 @@ func (wsl *WSListener) listenws(address v2net.Address, port v2net.Port) error {
errchan := make(chan 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() { go func() {
err := http.ListenAndServe(address.String()+":"+strconv.Itoa(int(port.Value())), nil) err := listenerfunc()
errchan <- err errchan <- err
return return
}() }()