use http/1.1 by default
All checks were successful
CI / build (push) Successful in 1m4s

http/2 is not useful for DASH video streaming.
This commit is contained in:
Fijxu 2025-03-10 22:53:25 -03:00
parent 83fff3d861
commit 81aa259a31
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 45 additions and 1 deletions

View file

@ -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 {

View file

@ -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 {