/
config.go
61 lines (52 loc) · 1.34 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package proxy
import (
"crypto/tls"
"net/http"
"net/url"
"time"
)
// time duration consts.
const (
DefaultDiaTimeout = 1 * time.Second
DefaultWSHeartInterval = 30 * time.Second
)
// supported http schemes
var supportedSchemes = map[string]bool{
SchemeHTTP: true,
SchemeHTTPS: true,
SchemeWebsocket: true,
SchemeWebsocketSec: true,
}
// Config for proxy.
type Config struct {
Base BaseConfig
WSHeartInterval time.Duration // websocket part: interval for websocket send ping package to keep alive.
HTTPMethod string // http part: which method to use for dialing, default: CONNECT.
}
// BaseConfig for proxy.
type BaseConfig struct {
TLSClientConfig *tls.Config // tls client config for https|wss
Header http.Header // http addon header
DialTimeout time.Duration // proxy dial timeout
}
// DefaultConfig return default config for common using, tls will skip tls verify.
func DefaultConfig(u *url.URL) *Config {
ret := &Config{
Base: BaseConfig{
DialTimeout: DefaultDiaTimeout,
},
WSHeartInterval: DefaultWSHeartInterval,
HTTPMethod: http.MethodConnect,
}
// set tls.
switch u.Scheme {
case SchemeHTTPS, SchemeWebsocketSec:
ret.Base.TLSClientConfig = &tls.Config{
ServerName: u.Hostname(),
InsecureSkipVerify: true,
}
default:
// nothing
}
return ret
}