diff --git a/client/src/http_sender.rs b/client/src/http_sender.rs index 71c788824c..84e1418d7a 100644 --- a/client/src/http_sender.rs +++ b/client/src/http_sender.rs @@ -47,11 +47,12 @@ impl HttpSender { /// The URL is an HTTP URL, usually for port 8899. pub fn new_with_timeout(url: U, timeout: Duration) -> Self { let mut default_headers = header::HeaderMap::new(); - let user_agent_string = - format!("rust-solana-client/{}", solana_version::Version::default()); default_headers.append( - header::USER_AGENT, - header::HeaderValue::from_str(user_agent_string.as_str()).unwrap(), + header::HeaderName::from_static("solana-client"), + header::HeaderValue::from_str( + format!("rust/{}", solana_version::Version::default()).as_str(), + ) + .unwrap(), ); let client = Arc::new( diff --git a/web3.js/rollup.config.js b/web3.js/rollup.config.js index 38f2e33f6a..e7e355a16e 100644 --- a/web3.js/rollup.config.js +++ b/web3.js/rollup.config.js @@ -71,6 +71,9 @@ function generateConfig(configType, format) { values: { 'process.env.NODE_ENV': JSON.stringify(env), 'process.env.BROWSER': JSON.stringify(browser), + 'process.env.npm_package_version': JSON.stringify( + process.env.npm_package_version, + ), }, }), ], diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 50fc8c2201..e3f3c45241 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -995,6 +995,7 @@ function createRpcClient( 'Content-Type': 'application/json', }, httpHeaders || {}, + COMMON_HTTP_HEADERS, ), }; @@ -2158,7 +2159,12 @@ export type ConfirmedSignatureInfo = { /** * An object defining headers to be passed to the RPC server */ -export type HttpHeaders = {[header: string]: string}; +export type HttpHeaders = { + [header: string]: string; +} & { + // Prohibited headers; for internal use only. + 'solana-client'?: never; +}; /** * The type of the JavaScript `fetch()` API @@ -2194,6 +2200,11 @@ export type ConnectionConfig = { confirmTransactionInitialTimeout?: number; }; +/** @internal */ +const COMMON_HTTP_HEADERS = { + 'solana-client': `js/${process.env.npm_package_version ?? 'UNKNOWN'}`, +}; + /** * A connection to a fullnode JSON RPC endpoint */