add option to force webhooks to be made over IPv4 (#1296)

* add option to force webhooks to be made over IPv4

* include in test

* changeset
This commit is contained in:
David Zhao
2025-11-09 15:22:14 -08:00
committed by GitHub
parent ad2cb9af44
commit 8b204ac683
5 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"github.com/livekit/protocol": patch
---
add option to only use IPv4 for webhooks

View File

@@ -185,6 +185,7 @@ type HTTPClientParams struct {
RetryWaitMax time.Duration
MaxRetries int
ClientTimeout time.Duration
ForceIPv4 bool
}
type FilterParams struct {

View File

@@ -21,6 +21,8 @@ import (
"encoding/base64"
"errors"
"fmt"
"net"
"net/http"
"sync"
"time"
@@ -130,6 +132,18 @@ func NewResourceURLNotifier(params ResourceURLNotifierParams) *ResourceURLNotifi
rhc.HTTPClient.Timeout = params.ClientTimeout
}
rhc.Logger = &logAdapter{}
if params.ForceIPv4 {
var tr *http.Transport
if existing, ok := rhc.HTTPClient.Transport.(*http.Transport); ok && existing != nil {
tr = existing.Clone()
} else {
tr = http.DefaultTransport.(*http.Transport).Clone()
}
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, "tcp4", addr)
}
rhc.HTTPClient.Transport = tr
}
r := &ResourceURLNotifier{
params: params,
client: rhc,

View File

@@ -20,6 +20,8 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"net"
"net/http"
"sync"
"time"
@@ -91,6 +93,18 @@ func NewURLNotifier(params URLNotifierParams) *URLNotifier {
if params.ClientTimeout > 0 {
rhc.HTTPClient.Timeout = params.ClientTimeout
}
if params.ForceIPv4 {
var tr *http.Transport
if existing, ok := rhc.HTTPClient.Transport.(*http.Transport); ok && existing != nil {
tr = existing.Clone()
} else {
tr = http.DefaultTransport.(*http.Transport).Clone()
}
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, "tcp4", addr)
}
rhc.HTTPClient.Transport = tr
}
n := &URLNotifier{
params: params,
client: rhc,

View File

@@ -229,6 +229,9 @@ func TestURLNotifierFilter(t *testing.T) {
Config: URLNotifierConfig{
QueueSize: 20,
},
HTTPClientParams: HTTPClientParams{
ForceIPv4: true,
},
})
defer urlNotifier.Stop(false)