From f022d9a47772ee911406e7ba9025b7f64605b293 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Tue, 13 Aug 2024 10:22:05 +0100 Subject: [PATCH] feat(rpc_user_agent)_: Added User Agent to the authed rpc client --- rpc/client.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index d2d9f9a35..7d0d43658 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "net/http" "net/url" "reflect" "sync" @@ -108,6 +109,11 @@ func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.U providerConfigs: providerConfigs, } + // TODO update user agent here + // Something like "status-go-rpc-client-upstream" + + gethrpc.DialOptions(context.Background(), c.upstreamURL) + if upstream.Enabled { c.UpstreamChainID = upstreamChainID c.upstreamEnabled = upstream.Enabled @@ -231,12 +237,17 @@ func (c *Client) getEthClents(network *params.Network) []*chain.EthClient { url := urls[key] if len(url) > 0 { - // For now we only support auth for status-proxy. + // For now, we only support auth for status-proxy. authStr, ok := authMap[key] var opts []gethrpc.ClientOption if ok { authEncoded := base64.StdEncoding.EncodeToString([]byte(authStr)) - opts = append(opts, gethrpc.WithHeader("Authorization", "Basic "+authEncoded)) + opts = append(opts, + gethrpc.WithHeaders(http.Header{ + "Authorization": {"Basic " + authEncoded}, + "User-Agent": {"status-go-rpc-client/2.0"}, + }), + ) } rpcClient, err = gethrpc.DialOptions(context.Background(), url, opts...) @@ -261,7 +272,7 @@ func (c *Client) getEthClents(network *params.Network) []*chain.EthClient { return ethClients } -// Ethclient returns ethclient.Client per chain +// EthClient returns ethclient.Client per chain func (c *Client) EthClient(chainID uint64) (chain.ClientInterface, error) { client, err := c.getClientUsingCache(chainID) if err != nil {