Skip to content

Commit

Permalink
fix issue #520
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed May 23, 2020
1 parent 6e46ac0 commit 2c0eb8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Transporter interface {
type DialOptions struct {
Timeout time.Duration
Chain *Chain
Host string
}

// DialOption allows a common way to set DialOptions.
Expand All @@ -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.
type HandshakeOptions struct {
Addr string
Expand Down
11 changes: 6 additions & 5 deletions cmd/gost/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,14 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
connector = gost.AutoConnector(node.User)
}

host := node.Get("host")
if host == "" {
host = node.Host
}

node.DialOptions = append(node.DialOptions,
gost.TimeoutDialOption(timeout),
gost.HostDialOption(host),
)

node.ConnectOptions = []gost.ConnectOption{
Expand All @@ -244,11 +250,6 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
gost.NoDelayConnectOption(node.GetBool("nodelay")),
}

host := node.Get("host")
if host == "" {
host = node.Host
}

sshConfig := &gost.SSHConfig{}
if s := node.Get("ssh_key"); s != "" {
key, err := gost.ParseSSHKeyFile(s)
Expand Down
6 changes: 3 additions & 3 deletions http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (tr *h2Transporter) Dial(addr string, options ...DialOption) (net.Conn, err

transport := http2.Transport{
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)
if err != nil {
return nil, err
Expand All @@ -256,13 +256,13 @@ func (tr *h2Transporter) Dial(addr string, options ...DialOption) (net.Conn, err
pr, pw := io.Pipe()
req := &http.Request{
Method: http.MethodConnect,
URL: &url.URL{Scheme: "https", Host: addr},
URL: &url.URL{Scheme: "https", Host: opts.Host},
Header: make(http.Header),
Proto: "HTTP/2.0",
ProtoMajor: 2,
ProtoMinor: 0,
Body: pr,
Host: addr,
Host: opts.Host,
ContentLength: -1,
}
if tr.path != "" {
Expand Down

0 comments on commit 2c0eb8d

Please sign in to comment.