Skip to content

Commit 81d3370

Browse files
committed
code:Allow Ignore SSL Verification in proxy
1 parent 947e08a commit 81d3370

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

internal/communicate/communicate.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package communicate
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
67
"encoding/binary"
78
"encoding/json"
89
"fmt"
@@ -44,23 +45,14 @@ func init() {
4445
}
4546

4647
type Communicate struct {
47-
text string
48-
voice string
49-
pitch string
50-
rate string
51-
volume string
52-
voiceLanguageRegion string
53-
54-
httpProxy string
55-
socket5Proxy string
56-
socket5ProxyUser string
57-
socket5ProxyPass string
48+
text string
5849

5950
audioDataIndex int
6051
prevIdx int
6152
shiftTime int
6253
finalUtterance map[int]int
6354
op chan map[string]interface{}
55+
opt *communicateOption.CommunicateOption
6456
}
6557

6658
type textEntry struct {
@@ -112,16 +104,8 @@ func NewCommunicate(text string, opt *communicateOption.CommunicateOption) (*Com
112104
return nil, err
113105
}
114106
return &Communicate{
115-
text: text,
116-
pitch: opt.Pitch,
117-
voice: opt.Voice,
118-
voiceLanguageRegion: opt.VoiceLangRegion,
119-
rate: opt.Rate,
120-
volume: opt.Volume,
121-
httpProxy: opt.HttpProxy,
122-
socket5Proxy: opt.Socket5Proxy,
123-
socket5ProxyUser: opt.Socket5ProxyUser,
124-
socket5ProxyPass: opt.Socket5ProxyPass,
107+
text: text,
108+
opt: opt,
125109
}, nil
126110
}
127111

@@ -173,7 +157,7 @@ func makeHeaders() http.Header {
173157
func (c *Communicate) stream() (<-chan map[string]interface{}, error) {
174158
texts := splitTextByByteLength(
175159
escape(removeIncompatibleCharacters(c.text)),
176-
calculateMaxMessageSize(c.pitch, c.voice, c.rate, c.volume),
160+
calculateMaxMessageSize(c.opt.Pitch, c.opt.Voice, c.opt.Rate, c.opt.Volume),
177161
)
178162
c.audioDataIndex = len(texts)
179163

@@ -236,7 +220,7 @@ func (c *Communicate) sendSSML(conn *websocket.Conn, currentTime string, text []
236220
ssmlHeadersAppendExtraData(
237221
generateConnectID(),
238222
currentTime,
239-
makeSsml(string(text), c.pitch, c.voice, c.rate, c.volume),
223+
makeSsml(string(text), c.opt.Pitch, c.opt.Voice, c.opt.Rate, c.opt.Volume),
240224
),
241225
))
242226
}
@@ -386,18 +370,21 @@ func sumWithMap(idx int, m map[int]int) int {
386370
}
387371

388372
func setupWebSocketProxy(dialer *websocket.Dialer, c *Communicate) {
389-
if c.httpProxy != "" {
390-
proxyUrl, _ := url.Parse(c.httpProxy)
373+
if c.opt.HttpProxy != "" {
374+
proxyUrl, _ := url.Parse(c.opt.HttpProxy)
391375
dialer.Proxy = http.ProxyURL(proxyUrl)
392376
}
393-
if c.socket5Proxy != "" {
394-
auth := &proxy.Auth{User: c.socket5ProxyUser, Password: c.socket5ProxyPass}
395-
socket5ProxyDialer, _ := proxy.SOCKS5("tcp", c.socket5Proxy, auth, proxy.Direct)
377+
if c.opt.Socket5Proxy != "" {
378+
auth := &proxy.Auth{User: c.opt.Socket5ProxyUser, Password: c.opt.Socket5ProxyPass}
379+
socket5ProxyDialer, _ := proxy.SOCKS5("tcp", c.opt.Socket5Proxy, auth, proxy.Direct)
396380
dialContext := func(ctx context.Context, network, address string) (net.Conn, error) {
397381
return socket5ProxyDialer.Dial(network, address)
398382
}
399383
dialer.NetDialContext = dialContext
400384
}
385+
if c.opt.IgnoreSSL {
386+
dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
387+
}
401388
}
402389

403390
func getMetaHubFrom(data []byte) (*metaHub, error) {

internal/communicateOption/option.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type CommunicateOption struct {
1717
Socket5Proxy string
1818
Socket5ProxyUser string
1919
Socket5ProxyPass string
20+
IgnoreSSL bool
2021
}
2122

2223
func (c *CommunicateOption) CheckAndApplyDefaultOption() {

option.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package edgetts
33
import "github.com/lib-x/edgetts/internal/communicateOption"
44

55
type option struct {
6-
Voice string
7-
VoiceLangRegion string
8-
Pitch string
9-
Rate string
10-
Volume string
11-
HttpProxy string
12-
Socket5Proxy string
13-
Socket5ProxyUser string
14-
Socket5ProxyPass string
6+
Voice string
7+
VoiceLangRegion string
8+
Pitch string
9+
Rate string
10+
Volume string
11+
HttpProxy string
12+
Socket5Proxy string
13+
Socket5ProxyUser string
14+
Socket5ProxyPass string
15+
IgnoreSSLVerification bool
1516
}
1617

1718
func (o *option) toInternalOption() *communicateOption.CommunicateOption {
@@ -25,6 +26,7 @@ func (o *option) toInternalOption() *communicateOption.CommunicateOption {
2526
Socket5Proxy: o.Socket5Proxy,
2627
Socket5ProxyUser: o.Socket5ProxyUser,
2728
Socket5ProxyPass: o.Socket5ProxyPass,
29+
IgnoreSSL: o.IgnoreSSLVerification,
2830
}
2931
}
3032

@@ -65,15 +67,26 @@ func WithVolume(volume string) Option {
6567
}
6668

6769
func WithHttpProxy(proxy string) Option {
70+
return WithHttpProxyEx(proxy, false)
71+
}
72+
73+
func WithHttpProxyEx(proxy string, ignoreSSLVerification bool) Option {
6874
return func(option *option) {
6975
option.HttpProxy = proxy
76+
option.IgnoreSSLVerification = ignoreSSLVerification
7077
}
7178
}
7279

7380
func WithSocket5Proxy(proxy, userName, password string) Option {
81+
return WithSocket5ProxyEx(proxy, userName, password, false)
82+
}
83+
84+
func WithSocket5ProxyEx(proxy, userName, password string, ignoreSSLVerification bool) Option {
7485
return func(option *option) {
7586
option.Socket5Proxy = proxy
7687
option.Socket5ProxyUser = userName
7788
option.Socket5ProxyPass = password
89+
option.IgnoreSSLVerification = ignoreSSLVerification
7890
}
91+
7992
}

0 commit comments

Comments
 (0)