Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eager-foxes-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"github.com/livekit/protocol": patch
---

add option to only use IPv4 for webhooks
1 change: 1 addition & 0 deletions webhook/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type HTTPClientParams struct {
RetryWaitMax time.Duration
MaxRetries int
ClientTimeout time.Duration
ForceIPv4 bool
}

type FilterParams struct {
Expand Down
14 changes: 14 additions & 0 deletions webhook/resource_url_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"encoding/base64"
"errors"
"fmt"
"net"
"net/http"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions webhook/url_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"crypto/sha256"
"encoding/base64"
"fmt"
"net"
"net/http"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func TestURLNotifierFilter(t *testing.T) {
Config: URLNotifierConfig{
QueueSize: 20,
},
HTTPClientParams: HTTPClientParams{
ForceIPv4: true,
},
})
defer urlNotifier.Stop(false)

Expand Down
Loading