-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathcreate_connection.ts
More file actions
57 lines (55 loc) · 1.65 KB
/
Copy pathcreate_connection.ts
File metadata and controls
57 lines (55 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { ConnectionParams } from '@clickhouse/client-common'
import type http from 'http'
import type https from 'node:https'
import type {
NodeBaseConnection,
NodeConnectionParams,
} from './node_base_connection'
import { NodeCustomAgentConnection } from './node_custom_agent_connection'
import { NodeHttpConnection } from './node_http_connection'
import { NodeHttpsConnection } from './node_https_connection'
export interface CreateConnectionParams {
connection_params: ConnectionParams
tls: NodeConnectionParams['tls']
keep_alive: NodeConnectionParams['keep_alive']
http_agent: http.Agent | https.Agent | undefined
set_basic_auth_header: boolean
capture_enhanced_stack_trace: boolean
}
export function createConnection({
connection_params,
tls,
keep_alive,
http_agent,
set_basic_auth_header,
capture_enhanced_stack_trace,
}: CreateConnectionParams): NodeBaseConnection {
if (http_agent !== undefined) {
return new NodeCustomAgentConnection({
...connection_params,
set_basic_auth_header,
capture_enhanced_stack_trace,
keep_alive, // only used to enforce proper KeepAlive headers
http_agent,
})
}
switch (connection_params.url.protocol) {
case 'http:':
return new NodeHttpConnection({
...connection_params,
set_basic_auth_header,
capture_enhanced_stack_trace,
keep_alive,
})
case 'https:':
return new NodeHttpsConnection({
...connection_params,
set_basic_auth_header,
capture_enhanced_stack_trace,
keep_alive,
tls,
})
default:
throw new Error('Only HTTP and HTTPS protocols are supported')
}
}