Skip to content

Commit

Permalink
feat: add custom version HTTP header string to RPC requests
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored and mergify[bot] committed Jun 29, 2022
1 parent 5790271 commit 6e009d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rollup.config.js
Expand Up @@ -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,
),
},
}),
],
Expand Down
13 changes: 12 additions & 1 deletion src/connection.ts
Expand Up @@ -995,6 +995,7 @@ function createRpcClient(
'Content-Type': 'application/json',
},
httpHeaders || {},
COMMON_HTTP_HEADERS,
),
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 6e009d8

Please sign in to comment.