fix HTTP2 multiplex
This commit is contained in:
parent
4f493a3383
commit
012932fab1
@ -194,8 +194,9 @@ func initChain() (*gost.Chain, error) {
|
|||||||
connector = gost.HTTPConnector(node.User)
|
connector = gost.HTTPConnector(node.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout, _ := strconv.Atoi(node.Values.Get("timeout"))
|
||||||
node.DialOptions = append(node.DialOptions,
|
node.DialOptions = append(node.DialOptions,
|
||||||
gost.TimeoutDialOption(gost.DialTimeout),
|
gost.TimeoutDialOption(time.Duration(timeout)*time.Second),
|
||||||
)
|
)
|
||||||
|
|
||||||
interval, _ := strconv.Atoi(node.Values.Get("ping"))
|
interval, _ := strconv.Atoi(node.Values.Get("ping"))
|
||||||
|
13
http2.go
13
http2.go
@ -37,15 +37,16 @@ func (c *http2Connector) Connect(conn net.Conn, addr string) (net.Conn, error) {
|
|||||||
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: cc.addr},
|
||||||
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: cc.addr,
|
||||||
ContentLength: -1,
|
ContentLength: -1,
|
||||||
}
|
}
|
||||||
|
req.Header.Set("Gost-Target", addr)
|
||||||
if c.User != nil {
|
if c.User != nil {
|
||||||
req.Header.Set("Proxy-Authorization",
|
req.Header.Set("Proxy-Authorization",
|
||||||
"Basic "+base64.StdEncoding.EncodeToString([]byte(c.User.String())))
|
"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{
|
transport := http2.Transport{
|
||||||
TLSClientConfig: tr.tlsConfig,
|
TLSClientConfig: tr.tlsConfig,
|
||||||
DialTLS: func(network, adr 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(adr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -270,7 +271,11 @@ func (h *http2Handler) Handle(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
|
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, ":") {
|
if !strings.Contains(target, ":") {
|
||||||
target += ":80"
|
target += ":80"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user