From 8782c1681be3c0eba44cda9ef206496474e3914e Mon Sep 17 00:00:00 2001 From: Thomas Boulos Date: Fri, 31 Jan 2025 15:20:54 -0800 Subject: [PATCH] add functions for proxy on adjust headers --- pkg/client/common/v1/websocket.go | 5 +++++ pkg/client/interfaces/v1/types-client.go | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/client/common/v1/websocket.go b/pkg/client/common/v1/websocket.go index ab9ec66b..cd6a4057 100644 --- a/pkg/client/common/v1/websocket.go +++ b/pkg/client/common/v1/websocket.go @@ -159,6 +159,9 @@ func (c *WSClient) internalConnectWithCancel(ctx context.Context, ctxCancel cont myHeader.Set("Host", c.cOptions.Host) myHeader.Set("Authorization", "token "+c.cOptions.APIKey) myHeader.Set("User-Agent", clientinterfaces.DgAgent) + if c.cOptions.WSHeaderProcessor != nil { + c.cOptions.WSHeaderProcessor(myHeader) + } // attempt to establish connection i := int64(0) @@ -196,6 +199,7 @@ func (c *WSClient) internalConnectWithCancel(ctx context.Context, ctxCancel cont dialer = websocket.Dialer{ HandshakeTimeout: 15 * time.Second, RedirectService: c.cOptions.RedirectService, + Proxy: c.cOptions.Proxy, } } else { dialer = websocket.Dialer{ @@ -204,6 +208,7 @@ func (c *WSClient) internalConnectWithCancel(ctx context.Context, ctxCancel cont TLSClientConfig: &tls.Config{InsecureSkipVerify: c.cOptions.SkipServerAuth}, RedirectService: c.cOptions.RedirectService, SkipServerAuth: c.cOptions.SkipServerAuth, + Proxy: c.cOptions.Proxy, } } // perform the websocket connection diff --git a/pkg/client/interfaces/v1/types-client.go b/pkg/client/interfaces/v1/types-client.go index 33029fe5..71c43010 100644 --- a/pkg/client/interfaces/v1/types-client.go +++ b/pkg/client/interfaces/v1/types-client.go @@ -4,13 +4,20 @@ package interfacesv1 +import ( + "net/http" + "net/url" +) + // ClientOptions defines any options for the client type ClientOptions struct { - APIKey string - Host string // override for the host endpoint - APIVersion string // override for the version used - Path string // override for the endpoint path usually or - SelfHosted bool // set to true if using on-prem + APIKey string + Host string // override for the host endpoint + APIVersion string // override for the version used + Path string // override for the endpoint path usually or + SelfHosted bool // set to true if using on-prem + Proxy func(*http.Request) (*url.URL, error) // provide function for proxy -- e.g. http.ProxyFromEnvironment + WSHeaderProcessor func(http.Header) // process headers before dialing for websocket connection // shared client options SkipServerAuth bool // keeps the client from authenticating with the server