From d5f6b83876f9c5cf0e39cc83fee6f5c5514f7a21 Mon Sep 17 00:00:00 2001 From: aderihoilya Date: Wed, 25 Sep 2024 00:05:26 +0300 Subject: [PATCH 1/3] feat: extra headers during initialization --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 18d02907..a3fdce18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,6 +62,7 @@ export type ConnectionOptions = { readonly session?: Session; readonly extraCredential?: ExtraCredential; readonly ssl?: SecureContextOptions; + extraHeaders?: RequestHeaders; }; export type QueryStage = { @@ -192,6 +193,7 @@ class Client { [TRINO_EXTRA_CREDENTIAL_HEADER]: encodeAsString( options.extraCredential ?? {} ), + ...(options.extraHeaders ?? {}), }; if (options.auth && options.auth.type === 'basic') { From c12d44e55996fc1d78501ad6b594fc5e523d9ab6 Mon Sep 17 00:00:00 2001 From: regadas Date: Mon, 4 Nov 2024 19:24:49 -0500 Subject: [PATCH 2/3] Add test --- tests/it/client.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/it/client.spec.ts b/tests/it/client.spec.ts index 827f2a61..1510d032 100644 --- a/tests/it/client.spec.ts +++ b/tests/it/client.spec.ts @@ -71,6 +71,22 @@ describe('trino', () => { expect(info.query).toBe(singleCustomerQuery); }); + test.concurrent('client extra header propagation', async () => { + const source = 'new-client'; + const trino = Trino.create({ + catalog: 'tpcds', + schema: 'sf100000', + auth: new BasicAuth('test'), + extraHeaders: {'X-Trino-Source': source}, + }); + + const query = await trino.query(singleCustomerQuery); + const qr = await query.next(); + + const info: any = await trino.queryInfo(qr.value.id); + expect(info.session.source).toBe(source); + }); + test.concurrent('query request header propagation', async () => { const trino = Trino.create({catalog: 'tpcds', auth: new BasicAuth('test')}); const query = await trino.query(useSchemaQuery); From 4bd7104617f1a575344d90ca20b3491f09ebe193 Mon Sep 17 00:00:00 2001 From: regadas Date: Mon, 4 Nov 2024 19:48:11 -0500 Subject: [PATCH 3/3] make it readonly --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a3fdce18..1928aaf3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,7 +62,7 @@ export type ConnectionOptions = { readonly session?: Session; readonly extraCredential?: ExtraCredential; readonly ssl?: SecureContextOptions; - extraHeaders?: RequestHeaders; + readonly extraHeaders?: RequestHeaders; }; export type QueryStage = {