Skip to content
Open
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
18 changes: 17 additions & 1 deletion rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func New(rpcEndpoint string) *Client {
return NewWithCustomRPCClient(rpcClient)
}

// New creates a new Solana JSON RPC client with the provided custom headers.
// NewWithHeaders creates a new Solana JSON RPC client with the provided custom headers.
// The provided headers will be added to each RPC request sent via this RPC client.
func NewWithHeaders(rpcEndpoint string, headers map[string]string) *Client {
opts := &jsonrpc.RPCClientOpts{
Expand All @@ -67,6 +67,22 @@ func NewWithHeaders(rpcEndpoint string, headers map[string]string) *Client {
return NewWithCustomRPCClient(rpcClient)
}

// NewWithHTTPClient creates a new Solana JSON RPC client with the provided httpClient.
// This is particularly useful when one wants to configure a proxy server without relying on
// the HTTP_PROXY/HTTPS_PROXY environment variables. http.ProxyFromEnvironment will ignore
// any HTTP_PROXY/HTTPS_PROXY setting if it resolves to localhost or any RFC1918 private IP
// which adds considerable friction when testing with a local proxy server
func NewWithHTTPClient(
rpcEndpoint string,
httpClient *http.Client,
) *Client {
opts := &jsonrpc.RPCClientOpts{
HTTPClient: httpClient,
}
rpcClient := jsonrpc.NewClientWithOpts(rpcEndpoint, opts)
return NewWithCustomRPCClient(rpcClient)
}

// Close closes the client.
func (cl *Client) Close() error {
if cl.rpcClient == nil {
Expand Down