@tramvai/module-http-proxy-agent 6.78.0 → 6.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,15 +10,17 @@ You need to install `@tramvai/module-http-proxy-agent`
10
10
  yarn add @tramvai/module-http-proxy-agent
11
11
  ```
12
12
 
13
- And connect in the project
13
+ And connect in the project **after** `@tramvai/module-http-client` module
14
14
 
15
15
  ```tsx
16
16
  import { createApp } from '@tramvai/core';
17
+ import { HttpClientModule } from '@tramvai/module-http-client';
17
18
  import { HttpProxyAgentModule } from '@tramvai/module-http-proxy-agent';
18
19
 
19
20
  createApp({
20
21
  name: 'tincoin',
21
- modules: [ HttpProxyAgentModule ],
22
+ // need to be placed after HttpClientModule to override HTTP_AGENT_TOKEN
23
+ modules: [HttpClientModule, HttpProxyAgentModule],
22
24
  });
23
25
  ```
24
26
 
package/lib/server.es.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { __decorate } from 'tslib';
2
- import { Module, commandLineListTokens } from '@tramvai/core';
2
+ import { Module, provide, optional, commandLineListTokens } from '@tramvai/core';
3
3
  import { LOGGER_TOKEN } from '@tramvai/tokens-common';
4
4
  import { METRICS_MODULE_TOKEN } from '@tramvai/tokens-metrics';
5
+ import { HTTP_CLIENT_AGENT, HTTP_CLIENT_AGENT_OPTIONS, HTTP_CLIENT_AGENT_INTERCEPTORS } from '@tramvai/tokens-http-client';
6
+ import { EnvHttpProxyAgent } from 'undici';
5
7
  import { httpProxyEnabled, getHttpsProxy, getNoProxy } from './utils/env.es.js';
6
8
  import { addProxyToHttpsAgent } from './add-proxy-to-https-agent/add-proxy-to-https-agent.es.js';
7
9
 
@@ -11,6 +13,44 @@ HttpProxyAgentModule = __decorate([
11
13
  Module({
12
14
  imports: [],
13
15
  providers: [
16
+ httpProxyEnabled() &&
17
+ provide({
18
+ provide: HTTP_CLIENT_AGENT,
19
+ useFactory: ({ options, interceptors, loggerFactory, metrics }) => {
20
+ loggerFactory('http-proxy-agent');
21
+ const proxyEnv = getHttpsProxy();
22
+ const noProxyEnv = getNoProxy();
23
+ // TODO: will work after https://github.com/nodejs/undici/pull/4659 release
24
+ // const metricsConnectionCounter = metrics.counter({
25
+ // name: 'http_proxy_undici_connect_total',
26
+ // help: 'Number of proxy connects with Undici',
27
+ // labelNames: ['host'],
28
+ // });
29
+ // diagnosticsChannel.channel('undici:proxy:connected').subscribe(({ connectParams }) => {
30
+ // logger.debug({
31
+ // event: 'proxy undici connection',
32
+ // connection: connectParams,
33
+ // });
34
+ // metricsConnectionCounter.inc({ host: new URL(connectParams.origin).host });
35
+ // });
36
+ const agent = new EnvHttpProxyAgent({
37
+ httpProxy: proxyEnv,
38
+ httpsProxy: proxyEnv,
39
+ noProxy: noProxyEnv,
40
+ ...options,
41
+ }).compose(...(interceptors ?? []));
42
+ return {
43
+ http: agent,
44
+ https: agent,
45
+ };
46
+ },
47
+ deps: {
48
+ options: HTTP_CLIENT_AGENT_OPTIONS,
49
+ interceptors: optional(HTTP_CLIENT_AGENT_INTERCEPTORS),
50
+ loggerFactory: LOGGER_TOKEN,
51
+ metrics: METRICS_MODULE_TOKEN,
52
+ },
53
+ }),
14
54
  httpProxyEnabled() && {
15
55
  provide: commandLineListTokens.init,
16
56
  multi: true,
package/lib/server.js CHANGED
@@ -6,6 +6,8 @@ var tslib = require('tslib');
6
6
  var core = require('@tramvai/core');
7
7
  var tokensCommon = require('@tramvai/tokens-common');
8
8
  var tokensMetrics = require('@tramvai/tokens-metrics');
9
+ var tokensHttpClient = require('@tramvai/tokens-http-client');
10
+ var undici = require('undici');
9
11
  var env = require('./utils/env.js');
10
12
  var addProxyToHttpsAgent = require('./add-proxy-to-https-agent/add-proxy-to-https-agent.js');
11
13
 
@@ -15,6 +17,44 @@ exports.HttpProxyAgentModule = tslib.__decorate([
15
17
  core.Module({
16
18
  imports: [],
17
19
  providers: [
20
+ env.httpProxyEnabled() &&
21
+ core.provide({
22
+ provide: tokensHttpClient.HTTP_CLIENT_AGENT,
23
+ useFactory: ({ options, interceptors, loggerFactory, metrics }) => {
24
+ loggerFactory('http-proxy-agent');
25
+ const proxyEnv = env.getHttpsProxy();
26
+ const noProxyEnv = env.getNoProxy();
27
+ // TODO: will work after https://github.com/nodejs/undici/pull/4659 release
28
+ // const metricsConnectionCounter = metrics.counter({
29
+ // name: 'http_proxy_undici_connect_total',
30
+ // help: 'Number of proxy connects with Undici',
31
+ // labelNames: ['host'],
32
+ // });
33
+ // diagnosticsChannel.channel('undici:proxy:connected').subscribe(({ connectParams }) => {
34
+ // logger.debug({
35
+ // event: 'proxy undici connection',
36
+ // connection: connectParams,
37
+ // });
38
+ // metricsConnectionCounter.inc({ host: new URL(connectParams.origin).host });
39
+ // });
40
+ const agent = new undici.EnvHttpProxyAgent({
41
+ httpProxy: proxyEnv,
42
+ httpsProxy: proxyEnv,
43
+ noProxy: noProxyEnv,
44
+ ...options,
45
+ }).compose(...(interceptors ?? []));
46
+ return {
47
+ http: agent,
48
+ https: agent,
49
+ };
50
+ },
51
+ deps: {
52
+ options: tokensHttpClient.HTTP_CLIENT_AGENT_OPTIONS,
53
+ interceptors: core.optional(tokensHttpClient.HTTP_CLIENT_AGENT_INTERCEPTORS),
54
+ loggerFactory: tokensCommon.LOGGER_TOKEN,
55
+ metrics: tokensMetrics.METRICS_MODULE_TOKEN,
56
+ },
57
+ }),
18
58
  env.httpProxyEnabled() && {
19
59
  provide: core.commandLineListTokens.init,
20
60
  multi: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-http-proxy-agent",
3
- "version": "6.78.0",
3
+ "version": "6.79.0",
4
4
  "description": "Enable support for http_proxy, https_proxy and no_proxy env variables",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -22,13 +22,18 @@
22
22
  "publishConfig": {
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
+ "devDependencies": {
26
+ "undici": "^7.16.0"
27
+ },
25
28
  "dependencies": {
26
- "@tramvai/tokens-common": "6.78.0"
29
+ "@tramvai/tokens-common": "6.79.0",
30
+ "@tramvai/tokens-http-client": "6.79.0",
31
+ "@tramvai/tokens-metrics": "6.79.0"
27
32
  },
28
33
  "peerDependencies": {
29
34
  "@tinkoff/dippy": "0.12.6",
30
- "@tramvai/core": "6.78.0",
31
- "@tramvai/tokens-metrics": "6.78.0",
32
- "tslib": "^2.4.0"
35
+ "@tramvai/core": "6.79.0",
36
+ "tslib": "^2.4.0",
37
+ "undici": "*"
33
38
  }
34
39
  }