add tls config option
This commit is contained in:
@ -19,21 +19,23 @@ func init() {
|
||||
}
|
||||
|
||||
type http2Dialer struct {
|
||||
md metadata
|
||||
clients map[string]*http.Client
|
||||
clientMutex sync.Mutex
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
options dialer.Options
|
||||
}
|
||||
|
||||
func NewDialer(opts ...dialer.Option) dialer.Dialer {
|
||||
options := &dialer.Options{}
|
||||
options := dialer.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
return &http2Dialer{
|
||||
clients: make(map[string]*http.Client),
|
||||
logger: options.Logger,
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +71,7 @@ func (d *http2Dialer) Dial(ctx context.Context, address string, opts ...dialer.D
|
||||
if !ok {
|
||||
client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: d.md.tlsConfig,
|
||||
TLSClientConfig: d.options.TLSConfig,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return d.dial(ctx, network, addr, options)
|
||||
},
|
||||
|
@ -27,33 +27,36 @@ func init() {
|
||||
type h2Dialer struct {
|
||||
clients map[string]*http.Client
|
||||
clientMutex sync.Mutex
|
||||
h2c bool
|
||||
logger logger.Logger
|
||||
md metadata
|
||||
h2c bool
|
||||
options dialer.Options
|
||||
}
|
||||
|
||||
func NewDialer(opts ...dialer.Option) dialer.Dialer {
|
||||
options := &dialer.Options{}
|
||||
options := dialer.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
return &h2Dialer{
|
||||
h2c: true,
|
||||
clients: make(map[string]*http.Client),
|
||||
logger: options.Logger,
|
||||
h2c: true,
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTLSDialer(opts ...dialer.Option) dialer.Dialer {
|
||||
options := &dialer.Options{}
|
||||
options := dialer.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
opt(&options)
|
||||
}
|
||||
|
||||
return &h2Dialer{
|
||||
clients: make(map[string]*http.Client),
|
||||
logger: options.Logger,
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +98,7 @@ func (d *h2Dialer) Dial(ctx context.Context, address string, opts ...dialer.Dial
|
||||
}
|
||||
} else {
|
||||
client.Transport = &http.Transport{
|
||||
TLSClientConfig: d.md.tlsConfig,
|
||||
TLSClientConfig: d.options.TLSConfig,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return d.dial(ctx, network, addr, options)
|
||||
},
|
||||
|
@ -1,42 +1,21 @@
|
||||
package h2
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
tls_util "github.com/go-gost/gost/pkg/common/util/tls"
|
||||
mdata "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
path string
|
||||
host string
|
||||
tlsConfig *tls.Config
|
||||
host string
|
||||
path string
|
||||
}
|
||||
|
||||
func (d *h2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
secure = "secure"
|
||||
serverName = "serverName"
|
||||
path = "path"
|
||||
)
|
||||
|
||||
d.md.host = mdata.GetString(md, serverName)
|
||||
sn, _, _ := net.SplitHostPort(d.md.host)
|
||||
if sn == "" {
|
||||
sn = "localhost"
|
||||
}
|
||||
d.md.tlsConfig, err = tls_util.LoadClientConfig(
|
||||
mdata.GetString(md, certFile),
|
||||
mdata.GetString(md, keyFile),
|
||||
mdata.GetString(md, caFile),
|
||||
mdata.GetBool(md, secure),
|
||||
sn,
|
||||
host = "host"
|
||||
path = "path"
|
||||
)
|
||||
|
||||
d.md.host = mdata.GetString(md, host)
|
||||
d.md.path = mdata.GetString(md, path)
|
||||
|
||||
return
|
||||
|
@ -1,37 +1,12 @@
|
||||
package http2
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
tls_util "github.com/go-gost/gost/pkg/common/util/tls"
|
||||
mdata "github.com/go-gost/gost/pkg/metadata"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
func (d *http2Dialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
certFile = "certFile"
|
||||
keyFile = "keyFile"
|
||||
caFile = "caFile"
|
||||
secure = "secure"
|
||||
serverName = "serverName"
|
||||
)
|
||||
|
||||
sn, _, _ := net.SplitHostPort(mdata.GetString(md, serverName))
|
||||
if sn == "" {
|
||||
sn = "localhost"
|
||||
}
|
||||
d.md.tlsConfig, err = tls_util.LoadClientConfig(
|
||||
mdata.GetString(md, certFile),
|
||||
mdata.GetString(md, keyFile),
|
||||
mdata.GetString(md, caFile),
|
||||
mdata.GetBool(md, secure),
|
||||
sn,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user