Closed DenScre closed 1 year ago
I'm afraid that this is currently not possible. FasthttpHTTPDialerTimeout
uses fasthttp.Dial
which always dials with DualStack disabled. Replacing it with DialDualStack
should work. You could try copying fasthttpproxy/http.go
into your own project and use this method instead. Let me know if that works and I'll change it in fasthttp as well.
I had the same problem,error : couldn't find DNS entries for the given domain. Try using DialDualStack But I found a way to support it, so I copied and replaced it myself, and it worked
func FasthttpHTTPDialerTimeoutWithIpv6(proxy string, timeout time.Duration) fasthttp.DialFunc {
var auth string
if strings.Contains(proxy, "@") {
index := strings.LastIndex(proxy, "@")
auth = base64.StdEncoding.EncodeToString([]byte(proxy[:index]))
proxy = proxy[index+1:]
}
return func(addr string) (net.Conn, error) {
var conn net.Conn
var err error
if timeout == 0 {
conn, err = fasthttp.DialDualStack(proxy)
} else {
conn, err = fasthttp.DialDualStackTimeout(proxy, timeout)
}
if err != nil {
return nil, err
}
req := "CONNECT " + addr + " HTTP/1.1\r\nHost: " + addr + "\r\n"
if auth != "" {
req += "Proxy-Authorization: Basic " + auth + "\r\n"
}
req += "\r\n"
if _, err := conn.Write([]byte(req)); err != nil {
return nil, err
}
res := fasthttp.AcquireResponse()
defer fasthttp.ReleaseResponse(res)
res.SkipBody = true
if err := res.Read(bufio.NewReader(conn)); err != nil {
conn.Close()
return nil, err
}
if res.Header.StatusCode() != 200 {
conn.Close()
return nil, fmt.Errorf("could not connect to proxy: %s status code: %d", proxy, res.Header.StatusCode())
}
return conn, nil
}
}
func FasthttpHTTPDialerTimeoutWithIpv6(proxy string, timeout time.Duration) fasthttp.DialFunc { var auth string if strings.Contains(proxy, "@") { index := strings.LastIndex(proxy, "@") auth = base64.StdEncoding.EncodeToString([]byte(proxy[:index])) proxy = proxy[index+1:] } return func(addr string) (net.Conn, error) { var conn net.Conn var err error if timeout == 0 { conn, err = fasthttp.DialDualStack(proxy) } else { conn, err = fasthttp.DialDualStackTimeout(proxy, timeout) } if err != nil { return nil, err } req := "CONNECT " + addr + " HTTP/1.1\r\nHost: " + addr + "\r\n" if auth != "" { req += "Proxy-Authorization: Basic " + auth + "\r\n" } req += "\r\n" if _, err := conn.Write([]byte(req)); err != nil { return nil, err } res := fasthttp.AcquireResponse() defer fasthttp.ReleaseResponse(res) res.SkipBody = true if err := res.Read(bufio.NewReader(conn)); err != nil { conn.Close() return nil, err } if res.Header.StatusCode() != 200 { conn.Close() return nil, fmt.Errorf("could not connect to proxy: %s status code: %d", proxy, res.Header.StatusCode()) } return conn, nil } }
It's ok for fasthttpproxy use ipv6, and mr : https://github.com/valyala/fasthttp/pull/1597
https://github.com/valyala/fasthttp/pull/1597 was merged.
Hello. I tried to transfer the implementation from net/http, but there was a problem, can you tell me how to correctly use ipv6 (system) to create requests.
In this case, if you replace Dial with 'Dial: fasthttpproxy.FasthttpHTTPDialerTimeout("127.0.0.1:3128", time.Second*10),', everything will work. (proxy that leads to '2001:DB8::9')
Displays an error (current ipv6 for example)