fix issue #520
This commit is contained in:
parent
d474a0c417
commit
145d45df4e
@ -83,6 +83,7 @@ type Transporter interface {
|
|||||||
type DialOptions struct {
|
type DialOptions struct {
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
Chain *Chain
|
Chain *Chain
|
||||||
|
Host string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialOption allows a common way to set DialOptions.
|
// DialOption allows a common way to set DialOptions.
|
||||||
@ -102,6 +103,13 @@ func ChainDialOption(chain *Chain) DialOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HostDialOption specifies the host used by Transporter.Dial
|
||||||
|
func HostDialOption(host string) DialOption {
|
||||||
|
return func(opts *DialOptions) {
|
||||||
|
opts.Host = host
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HandshakeOptions describes the options for handshake.
|
// HandshakeOptions describes the options for handshake.
|
||||||
type HandshakeOptions struct {
|
type HandshakeOptions struct {
|
||||||
Addr string
|
Addr string
|
||||||
|
@ -234,8 +234,14 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
|
|||||||
connector = gost.AutoConnector(node.User)
|
connector = gost.AutoConnector(node.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host := node.Get("host")
|
||||||
|
if host == "" {
|
||||||
|
host = node.Host
|
||||||
|
}
|
||||||
|
|
||||||
node.DialOptions = append(node.DialOptions,
|
node.DialOptions = append(node.DialOptions,
|
||||||
gost.TimeoutDialOption(timeout),
|
gost.TimeoutDialOption(timeout),
|
||||||
|
gost.HostDialOption(host),
|
||||||
)
|
)
|
||||||
|
|
||||||
node.ConnectOptions = []gost.ConnectOption{
|
node.ConnectOptions = []gost.ConnectOption{
|
||||||
@ -244,11 +250,6 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
|
|||||||
gost.NoDelayConnectOption(node.GetBool("nodelay")),
|
gost.NoDelayConnectOption(node.GetBool("nodelay")),
|
||||||
}
|
}
|
||||||
|
|
||||||
host := node.Get("host")
|
|
||||||
if host == "" {
|
|
||||||
host = node.Host
|
|
||||||
}
|
|
||||||
|
|
||||||
sshConfig := &gost.SSHConfig{}
|
sshConfig := &gost.SSHConfig{}
|
||||||
if s := node.Get("ssh_key"); s != "" {
|
if s := node.Get("ssh_key"); s != "" {
|
||||||
key, err := gost.ParseSSHKeyFile(s)
|
key, err := gost.ParseSSHKeyFile(s)
|
||||||
|
6
http2.go
6
http2.go
@ -234,7 +234,7 @@ func (tr *h2Transporter) Dial(addr string, options ...DialOption) (net.Conn, err
|
|||||||
|
|
||||||
transport := http2.Transport{
|
transport := http2.Transport{
|
||||||
TLSClientConfig: tr.tlsConfig,
|
TLSClientConfig: tr.tlsConfig,
|
||||||
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
|
DialTLS: func(network, adr string, cfg *tls.Config) (net.Conn, error) {
|
||||||
conn, err := opts.Chain.Dial(addr)
|
conn, err := opts.Chain.Dial(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -256,13 +256,13 @@ func (tr *h2Transporter) Dial(addr string, options ...DialOption) (net.Conn, err
|
|||||||
pr, pw := io.Pipe()
|
pr, pw := io.Pipe()
|
||||||
req := &http.Request{
|
req := &http.Request{
|
||||||
Method: http.MethodConnect,
|
Method: http.MethodConnect,
|
||||||
URL: &url.URL{Scheme: "https", Host: addr},
|
URL: &url.URL{Scheme: "https", Host: opts.Host},
|
||||||
Header: make(http.Header),
|
Header: make(http.Header),
|
||||||
Proto: "HTTP/2.0",
|
Proto: "HTTP/2.0",
|
||||||
ProtoMajor: 2,
|
ProtoMajor: 2,
|
||||||
ProtoMinor: 0,
|
ProtoMinor: 0,
|
||||||
Body: pr,
|
Body: pr,
|
||||||
Host: addr,
|
Host: opts.Host,
|
||||||
ContentLength: -1,
|
ContentLength: -1,
|
||||||
}
|
}
|
||||||
if tr.path != "" {
|
if tr.path != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user