소스 검색

Support Listen WebSocket with TLS

Shelikhoo 9 년 전
부모
커밋
16b529093d
2개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 0
      transport/internet/ws/config_json.go
  2. 11 1
      transport/internet/ws/hub.go

+ 4 - 0
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
 }

+ 11 - 1
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
 	}()