feat(rpc_user_agent)_: Added User Agent to the authed rpc client

This commit is contained in:
Samuel Hawksby-Robinson 2024-08-13 10:22:05 +01:00
parent dd443b030d
commit f022d9a477
1 changed files with 14 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http"
"net/url" "net/url"
"reflect" "reflect"
"sync" "sync"
@ -108,6 +109,11 @@ func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.U
providerConfigs: providerConfigs, providerConfigs: providerConfigs,
} }
// TODO update user agent here
// Something like "status-go-rpc-client-upstream"
gethrpc.DialOptions(context.Background(), c.upstreamURL)
if upstream.Enabled { if upstream.Enabled {
c.UpstreamChainID = upstreamChainID c.UpstreamChainID = upstreamChainID
c.upstreamEnabled = upstream.Enabled c.upstreamEnabled = upstream.Enabled
@ -231,12 +237,17 @@ func (c *Client) getEthClents(network *params.Network) []*chain.EthClient {
url := urls[key] url := urls[key]
if len(url) > 0 { 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] authStr, ok := authMap[key]
var opts []gethrpc.ClientOption var opts []gethrpc.ClientOption
if ok { if ok {
authEncoded := base64.StdEncoding.EncodeToString([]byte(authStr)) 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...) rpcClient, err = gethrpc.DialOptions(context.Background(), url, opts...)
@ -261,7 +272,7 @@ func (c *Client) getEthClents(network *params.Network) []*chain.EthClient {
return ethClients return ethClients
} }
// Ethclient returns ethclient.Client per chain // EthClient returns ethclient.Client per chain
func (c *Client) EthClient(chainID uint64) (chain.ClientInterface, error) { func (c *Client) EthClient(chainID uint64) (chain.ClientInterface, error) {
client, err := c.getClientUsingCache(chainID) client, err := c.getClientUsingCache(chainID)
if err != nil { if err != nil {