Skip to content

Commit fc6e992

Browse files
committed
[WAHA] Force ipv4
1 parent e6fd89a commit fc6e992

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {
221221
log = waLog.Noop
222222
}
223223
uniqueIDPrefix := random.Bytes(2)
224+
transport := http.DefaultTransport.(*http.Transport).Clone()
225+
transport.DialContext = DialContextIPv4
224226
baseHTTPClient := &http.Client{
225-
Transport: (http.DefaultTransport.(*http.Transport)).Clone(),
227+
Transport: transport,
226228
}
227229
cli := &Client{
228230
mediaHTTP: ptr.Clone(baseHTTPClient),
@@ -336,6 +338,7 @@ func (cli *Client) SetProxy(proxy Proxy, opts ...SetProxyOptions) {
336338
}
337339
transport := (http.DefaultTransport.(*http.Transport)).Clone()
338340
transport.Proxy = proxy
341+
transport.DialContext = DialContextIPv4
339342
cli.setTransport(transport, opt)
340343
}
341344

ipv4.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package whatsmeow
2+
3+
import (
4+
"context"
5+
"net"
6+
"time"
7+
)
8+
9+
func DialContextIPv4(ctx context.Context, network, addr string) (net.Conn, error) {
10+
return (&net.Dialer{
11+
Timeout: 90 * time.Second,
12+
KeepAlive: 30 * time.Second,
13+
}).DialContext(ctx, "tcp4", addr)
14+
}

0 commit comments

Comments
 (0)