feat(rpc_user_agent)_: Added application version to the RPC user client
This commit is contained in:
parent
c257874be9
commit
0e882f1b97
|
@ -10,7 +10,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -18,6 +17,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
|
appCommon "github.com/status-im/status-go/common"
|
||||||
"github.com/status-im/status-go/params"
|
"github.com/status-im/status-go/params"
|
||||||
"github.com/status-im/status-go/rpc/chain"
|
"github.com/status-im/status-go/rpc/chain"
|
||||||
"github.com/status-im/status-go/rpc/network"
|
"github.com/status-im/status-go/rpc/network"
|
||||||
|
@ -34,13 +34,16 @@ const (
|
||||||
providerInfura = "infura"
|
providerInfura = "infura"
|
||||||
ProviderStatusProxy = "status-proxy"
|
ProviderStatusProxy = "status-proxy"
|
||||||
|
|
||||||
|
mobile = "mobile"
|
||||||
|
desktop = "desktop"
|
||||||
|
|
||||||
// rpcUserAgentFormat 'procurator': *an agent representing others*, aka a "proxy"
|
// rpcUserAgentFormat 'procurator': *an agent representing others*, aka a "proxy"
|
||||||
// allows for the rpc client to have a dedicated user agent, which is useful for the proxy server logs.
|
// allows for the rpc client to have a dedicated user agent, which is useful for the proxy server logs.
|
||||||
rpcUserAgentFormat = "procuratee-%s/1.0"
|
rpcUserAgentFormat = "procuratee-%s/%s"
|
||||||
|
|
||||||
// rpcUserAgentUpstreamFormat a separate user agent format for upstream, because we should not be using upstream
|
// rpcUserAgentUpstreamFormat a separate user agent format for upstream, because we should not be using upstream
|
||||||
// if we see this user agent in the logs that means parts of the application are using a malconfigured http client
|
// if we see this user agent in the logs that means parts of the application are using a malconfigured http client
|
||||||
rpcUserAgentUpstreamFormat = "procuratee-%s-upstream/1.0"
|
rpcUserAgentUpstreamFormat = "procuratee-%s-upstream/%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List of RPC client errors.
|
// List of RPC client errors.
|
||||||
|
@ -50,20 +53,17 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// rpcUserAgentName the user agent
|
// rpcUserAgentName the user agent
|
||||||
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, "no-GOOS")
|
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, "no-GOOS", params.Version)
|
||||||
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, "no-GOOS")
|
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, "no-GOOS", params.Version)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
switch runtime.GOOS {
|
if appCommon.IsMobilePlatform() {
|
||||||
case "android", "ios":
|
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, mobile, params.Version)
|
||||||
mobile := "mobile"
|
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, mobile, params.Version)
|
||||||
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, mobile)
|
} else {
|
||||||
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, mobile)
|
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, desktop, params.Version)
|
||||||
default:
|
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, desktop, params.Version)
|
||||||
desktop := "desktop"
|
|
||||||
rpcUserAgentName = fmt.Sprintf(rpcUserAgentFormat, desktop)
|
|
||||||
rpcUserAgentUpstreamName = fmt.Sprintf(rpcUserAgentUpstreamFormat, desktop)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,6 @@ func TestGetClientsUsingCache(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserAgent(t *testing.T) {
|
func TestUserAgent(t *testing.T) {
|
||||||
require.Equal(t, "procuratee-desktop/1.0", rpcUserAgentName)
|
require.Equal(t, "procuratee-desktop/", rpcUserAgentName)
|
||||||
require.Equal(t, "procuratee-desktop-upstream/1.0", rpcUserAgentUpstreamName)
|
require.Equal(t, "procuratee-desktop-upstream/", rpcUserAgentUpstreamName)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue