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:
5
.changeset/eager-foxes-allow.md
Normal file
5
.changeset/eager-foxes-allow.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"github.com/livekit/protocol": patch
|
||||
---
|
||||
|
||||
add option to only use IPv4 for webhooks
|
||||
@@ -185,6 +185,7 @@ type HTTPClientParams struct {
|
||||
RetryWaitMax time.Duration
|
||||
MaxRetries int
|
||||
ClientTimeout time.Duration
|
||||
ForceIPv4 bool
|
||||
}
|
||||
|
||||
type FilterParams struct {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -229,6 +229,9 @@ func TestURLNotifierFilter(t *testing.T) {
|
||||
Config: URLNotifierConfig{
|
||||
QueueSize: 20,
|
||||
},
|
||||
HTTPClientParams: HTTPClientParams{
|
||||
ForceIPv4: true,
|
||||
},
|
||||
})
|
||||
defer urlNotifier.Stop(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user