diff --git a/rpc/client.go b/rpc/client.go index 722e0e58c..a8e0b6e2a 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -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{ @@ -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 {