Skip to content

Commit 66a9e9d

Browse files
aderihoJDregadas
andauthored
feat: extra headers during initialization (#668)
Co-authored-by: regadas <[email protected]>
1 parent 657084a commit 66a9e9d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type ConnectionOptions = {
6262
readonly session?: Session;
6363
readonly extraCredential?: ExtraCredential;
6464
readonly ssl?: SecureContextOptions;
65+
readonly extraHeaders?: RequestHeaders;
6566
};
6667

6768
export type QueryStage = {
@@ -192,6 +193,7 @@ class Client {
192193
[TRINO_EXTRA_CREDENTIAL_HEADER]: encodeAsString(
193194
options.extraCredential ?? {}
194195
),
196+
...(options.extraHeaders ?? {}),
195197
};
196198

197199
if (options.auth && options.auth.type === 'basic') {

tests/it/client.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ describe('trino', () => {
7171
expect(info.query).toBe(singleCustomerQuery);
7272
});
7373

74+
test.concurrent('client extra header propagation', async () => {
75+
const source = 'new-client';
76+
const trino = Trino.create({
77+
catalog: 'tpcds',
78+
schema: 'sf100000',
79+
auth: new BasicAuth('test'),
80+
extraHeaders: {'X-Trino-Source': source},
81+
});
82+
83+
const query = await trino.query(singleCustomerQuery);
84+
const qr = await query.next();
85+
86+
const info: any = await trino.queryInfo(qr.value.id);
87+
expect(info.session.source).toBe(source);
88+
});
89+
7490
test.concurrent('query request header propagation', async () => {
7591
const trino = Trino.create({catalog: 'tpcds', auth: new BasicAuth('test')});
7692
const query = await trino.query(useSchemaQuery);

0 commit comments

Comments
 (0)