Add option to disable ipv6.
This commit is contained in:
parent
cae96be92a
commit
0816001b24
1 changed files with 15 additions and 4 deletions
19
main.go
19
main.go
|
@ -24,13 +24,20 @@ var h3client = &http.Client{
|
||||||
Transport: &http3.RoundTripper{},
|
Transport: &http3.RoundTripper{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dialer = &net.Dialer{
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
KeepAlive: 30 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
// http/2 client
|
// http/2 client
|
||||||
var h2client = &http.Client{
|
var h2client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
Dial: (&net.Dialer{
|
Dial: func(network, addr string) (net.Conn, error) {
|
||||||
Timeout: 30 * time.Second,
|
if disable_ipv6 {
|
||||||
KeepAlive: 30 * time.Second,
|
network = "tcp4"
|
||||||
}).Dial,
|
}
|
||||||
|
return dialer.Dial(network, addr)
|
||||||
|
},
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
ResponseHeaderTimeout: 20 * time.Second,
|
ResponseHeaderTimeout: 20 * time.Second,
|
||||||
ExpectContinueTimeout: 1 * time.Second,
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
|
@ -70,6 +77,8 @@ var path_prefix = ""
|
||||||
|
|
||||||
var manifest_re = regexp.MustCompile(`(?m)URI="([^"]+)"`)
|
var manifest_re = regexp.MustCompile(`(?m)URI="([^"]+)"`)
|
||||||
|
|
||||||
|
var disable_ipv6 = false
|
||||||
|
|
||||||
type requesthandler struct{}
|
type requesthandler struct{}
|
||||||
|
|
||||||
func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (*requesthandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -292,6 +301,8 @@ func RelativeUrl(in string) (newurl string) {
|
||||||
func main() {
|
func main() {
|
||||||
path_prefix = os.Getenv("PREFIX_PATH")
|
path_prefix = os.Getenv("PREFIX_PATH")
|
||||||
|
|
||||||
|
disable_ipv6 = os.Getenv("DISABLE_IPV6") == "1"
|
||||||
|
|
||||||
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
socket := "socket" + string(os.PathSeparator) + "http-proxy.sock"
|
||||||
syscall.Unlink(socket)
|
syscall.Unlink(socket)
|
||||||
listener, err := net.Listen("unix", socket)
|
listener, err := net.Listen("unix", socket)
|
||||||
|
|
Loading…
Add table
Reference in a new issue