Skip to content

Commit

Permalink
add functions for proxy on adjust headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tomboulossf committed Jan 31, 2025
1 parent 42c3486 commit 8782c16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pkg/client/common/v1/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions pkg/client/interfaces/v1/types-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version/listen> or <version/projects>
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 <version/listen> or <version/projects>
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
Expand Down

0 comments on commit 8782c16

Please sign in to comment.