Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 6e009d8

Browse files
steveluschermergify[bot]
authored andcommittedJun 29, 2022
feat: add custom version HTTP header string to RPC requests
1 parent 5790271 commit 6e009d8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ function generateConfig(configType, format) {
7171
values: {
7272
'process.env.NODE_ENV': JSON.stringify(env),
7373
'process.env.BROWSER': JSON.stringify(browser),
74+
'process.env.npm_package_version': JSON.stringify(
75+
process.env.npm_package_version,
76+
),
7477
},
7578
}),
7679
],

‎src/connection.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ function createRpcClient(
995995
'Content-Type': 'application/json',
996996
},
997997
httpHeaders || {},
998+
COMMON_HTTP_HEADERS,
998999
),
9991000
};
10001001

@@ -2158,7 +2159,12 @@ export type ConfirmedSignatureInfo = {
21582159
/**
21592160
* An object defining headers to be passed to the RPC server
21602161
*/
2161-
export type HttpHeaders = {[header: string]: string};
2162+
export type HttpHeaders = {
2163+
[header: string]: string;
2164+
} & {
2165+
// Prohibited headers; for internal use only.
2166+
'solana-client'?: never;
2167+
};
21622168

21632169
/**
21642170
* The type of the JavaScript `fetch()` API
@@ -2194,6 +2200,11 @@ export type ConnectionConfig = {
21942200
confirmTransactionInitialTimeout?: number;
21952201
};
21962202

2203+
/** @internal */
2204+
const COMMON_HTTP_HEADERS = {
2205+
'solana-client': `js/${process.env.npm_package_version ?? 'UNKNOWN'}`,
2206+
};
2207+
21972208
/**
21982209
* A connection to a fullnode JSON RPC endpoint
21992210
*/

0 commit comments

Comments
 (0)
This repository has been archived.