diff --git a/cmd/gost/main.go b/cmd/gost/main.go index 8efb8ee..4165556 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -194,8 +194,9 @@ func initChain() (*gost.Chain, error) { connector = gost.HTTPConnector(node.User) } + timeout, _ := strconv.Atoi(node.Values.Get("timeout")) node.DialOptions = append(node.DialOptions, - gost.TimeoutDialOption(gost.DialTimeout), + gost.TimeoutDialOption(time.Duration(timeout)*time.Second), ) interval, _ := strconv.Atoi(node.Values.Get("ping")) diff --git a/http2.go b/http2.go index aef66e0..d63b443 100644 --- a/http2.go +++ b/http2.go @@ -37,15 +37,16 @@ func (c *http2Connector) Connect(conn net.Conn, addr string) (net.Conn, error) { pr, pw := io.Pipe() req := &http.Request{ Method: http.MethodConnect, - URL: &url.URL{Scheme: "https", Host: addr}, + URL: &url.URL{Scheme: "https", Host: cc.addr}, Header: make(http.Header), Proto: "HTTP/2.0", ProtoMajor: 2, ProtoMinor: 0, Body: pr, - Host: addr, + Host: cc.addr, ContentLength: -1, } + req.Header.Set("Gost-Target", addr) if c.User != nil { req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(c.User.String()))) @@ -107,7 +108,7 @@ func (tr *http2Transporter) Dial(addr string, options ...DialOption) (net.Conn, transport := http2.Transport{ TLSClientConfig: tr.tlsConfig, DialTLS: func(network, adr string, cfg *tls.Config) (net.Conn, error) { - conn, err := opts.Chain.Dial(addr) + conn, err := opts.Chain.Dial(adr) if err != nil { return nil, err } @@ -270,7 +271,11 @@ func (h *http2Handler) Handle(conn net.Conn) { } func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) { - target := r.Host + target := r.Header.Get("Gost-Target") + if target == "" { + target = r.Host + } + if !strings.Contains(target, ":") { target += ":80" }