Skip to content

Commit

Permalink
Prepare 0.2.9; Cleanup tests and restrict the headers type to string …
Browse files Browse the repository at this point in the history
…only
  • Loading branch information
slvrtrn committed Jan 19, 2024
1 parent 9b358ea commit 8b3d134
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 798 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 0.2.9 (Common, Node.js, Web)

### New features

- It is now possible to set additional HTTP headers for outgoing ClickHouse requests. This might be useful if, for example, you use a reverse proxy with authorization. ([@teawithfruit](https://github.com/teawithfruit), [#224](https://github.com/ClickHouse/clickhouse-js/pull/224))

```ts
const client = createClient({
additional_headers: {
'X-ClickHouse-User': 'clickhouse_user',
'X-ClickHouse-Key': 'clickhouse_password',
},
})
```

## 0.2.8 (Common, Node.js, Web)

### New features
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface ClickHouseClientConfigOptions<Stream> {
level?: ClickHouseLogLevel
}
session_id?: string
additional_headers?: Record<string, number | string | string[]>
additional_headers?: Record<string, string>
}

export type BaseClickHouseClientConfigOptions<Stream> = Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ConnectionParams {
clickhouse_settings: ClickHouseSettings
logWriter: LogWriter
application_id?: string
additional_headers?: Record<string, number | string | string[]>
additional_headers?: Record<string, string>
}

export interface ConnBaseQueryParams {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '0.2.8'
export default '0.2.9'
55 changes: 55 additions & 0 deletions packages/client-node/__tests__/integration/node_client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Http from 'http'
import type Stream from 'stream'
import type { ClickHouseClient } from '../../src'
import { createClient } from '../../src'
import { emitResponseBody, stubClientRequest } from '../utils/http_stubs'

describe('[Node.js] Client', () => {
let httpRequestStub: jasmine.Spy<typeof Http.request>
let clientRequest: Http.ClientRequest
beforeEach(() => {
clientRequest = stubClientRequest()
httpRequestStub = spyOn(Http, 'request').and.returnValue(clientRequest)
})

describe('Additional headers', () => {
it('should be possible to set additional_headers', async () => {
const client = createClient({
additional_headers: {
'Test-Header': 'foobar',
},
})
await query(client)

expect(httpRequestStub).toHaveBeenCalledTimes(1)
const calledWith = httpRequestStub.calls.mostRecent().args[1]
expect(calledWith.headers).toEqual({
Authorization: 'Basic ZGVmYXVsdDo=', // default user with empty password
'Accept-Encoding': 'gzip',
'Test-Header': 'foobar',
'User-Agent': jasmine.stringContaining('clickhouse-js'),
})
})

it('should work without additional headers', async () => {
const client = createClient({})
await query(client)

expect(httpRequestStub).toHaveBeenCalledTimes(1)
const calledWith = httpRequestStub.calls.mostRecent().args[1]
expect(calledWith.headers).toEqual({
Authorization: 'Basic ZGVmYXVsdDo=', // default user with empty password
'Accept-Encoding': 'gzip',
'User-Agent': jasmine.stringContaining('clickhouse-js'),
})
})
})

async function query(client: ClickHouseClient<Stream.Readable>) {
const selectPromise = client.query({
query: 'SELECT * FROM system.numbers LIMIT 5',
})
emitResponseBody(clientRequest, 'hi')
await selectPromise
}
})
102 changes: 0 additions & 102 deletions packages/client-node/__tests__/integration/node_connection.test.ts

This file was deleted.

Loading

0 comments on commit 8b3d134

Please sign in to comment.