diff --git a/cmd/http3-ytproxy/main.go b/cmd/http3-ytproxy/main.go index 050f397..e9a28bf 100644 --- a/cmd/http3-ytproxy/main.go +++ b/cmd/http3-ytproxy/main.go @@ -153,6 +153,7 @@ func main() { var http_server bool = true var https bool = false var h3c bool = false + var h2c bool = false var ipv6 bool = false var bc bool = true @@ -162,6 +163,9 @@ func main() { if strings.ToLower(getenv("HTTPS")) == "true" { https = true } + if strings.ToLower(getenv("H2C")) == "true" { + h2c = true + } if strings.ToLower(getenv("H3C")) == "true" { h3c = true } @@ -219,9 +223,14 @@ func main() { httpc.Ipv6_only = ipv6 if h3c { + log.Println("[INFO] Using HTTP/3 Client") httpc.Client = httpc.H3client - } else { + } else if h2c { + log.Println("[INFO] Using HTTP/2 Client") httpc.Client = httpc.H2client + } else { + log.Println("[INFO] Using HTTP/1.1 Client") + httpc.Client = httpc.H1_1client } if https { diff --git a/internal/httpc/client.go b/internal/httpc/client.go index f3b891f..2bcc1f3 100644 --- a/internal/httpc/client.go +++ b/internal/httpc/client.go @@ -1,6 +1,7 @@ package httpc import ( + "crypto/tls" "net" "net/http" "net/url" @@ -25,6 +26,40 @@ var H3client = &http.Client{ Timeout: 10 * time.Second, } +// http/1.1 client +var H1_1client = &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + Transport: &http.Transport{ + Dial: func(network, addr string) (net.Conn, error) { + var net string + if Ipv6_only { + net = "tcp6" + } else { + net = "tcp4" + } + return dialer.Dial(net, addr) + }, + TLSHandshakeTimeout: 10 * time.Second, + ResponseHeaderTimeout: 20 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + IdleConnTimeout: 30 * time.Second, + ReadBufferSize: 16 * 1024, + MaxConnsPerHost: 0, + MaxIdleConnsPerHost: 10, + MaxIdleConns: 0, + Proxy: func(r *http.Request) (*url.URL, error) { + if Proxy != "" { + return url.Parse(Proxy) + } + return nil, nil + }, + // Prevent switching to HTTP/2 + TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper), + }, +} + // http/2 client var H2client = &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error {