@florianpat/lando-core 3.23.22-test2 → 3.23.27-1florianPat.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/CHANGELOG.md +23 -1
- package/app.js +2 -0
- package/builders/_init.js +2 -2
- package/builders/_lando.js +19 -6
- package/builders/lando-v4.js +3 -0
- package/config.yml +4 -4
- package/hooks/app-run-events.js +23 -1
- package/hooks/lando-setup-build-engine-darwin.js +3 -0
- package/hooks/lando-setup-build-engine-win32.js +2 -0
- package/hooks/lando-setup-build-engine-wsl.js +2 -0
- package/hooks/lando-setup-orchestrator.js +2 -2
- package/lib/app.js +15 -4
- package/lib/daemon.js +1 -1
- package/lib/docker.js +1 -1
- package/lib/updates.js +9 -1
- package/netlify.toml +1 -0
- package/node_modules/undici/docs/docs/api/Dispatcher.md +51 -0
- package/node_modules/undici/index.js +2 -1
- package/node_modules/undici/lib/api/api-request.js +1 -1
- package/node_modules/undici/lib/core/connect.js +5 -0
- package/node_modules/undici/lib/dispatcher/client-h2.js +20 -6
- package/node_modules/undici/lib/handler/retry-handler.js +3 -3
- package/node_modules/undici/lib/interceptor/dns.js +375 -0
- package/node_modules/undici/lib/web/cache/cache.js +1 -0
- package/node_modules/undici/lib/web/cache/cachestorage.js +2 -0
- package/node_modules/undici/lib/web/eventsource/eventsource.js +2 -0
- package/node_modules/undici/lib/web/fetch/body.js +9 -1
- package/node_modules/undici/lib/web/fetch/formdata.js +2 -0
- package/node_modules/undici/lib/web/fetch/headers.js +2 -0
- package/node_modules/undici/lib/web/fetch/index.js +1 -1
- package/node_modules/undici/lib/web/fetch/request.js +1 -0
- package/node_modules/undici/lib/web/fetch/response.js +1 -0
- package/node_modules/undici/lib/web/fetch/webidl.js +2 -0
- package/node_modules/undici/lib/web/websocket/events.js +4 -0
- package/node_modules/undici/lib/web/websocket/websocket.js +2 -0
- package/node_modules/undici/package.json +1 -1
- package/node_modules/undici/types/interceptors.d.ts +14 -0
- package/node_modules/undici/types/retry-handler.d.ts +1 -1
- package/node_modules/undici/types/webidl.d.ts +6 -0
- package/package.json +6 -6
- package/release-aliases/3-EDGE +1 -1
- package/release-aliases/3-STABLE +1 -1
- package/scripts/install-docker-desktop.sh +1 -1
- package/scripts/install-docker-engine.sh +1 -1
- package/scripts/lando-entrypoint.sh +1 -1
- package/utils/build-tooling-task.js +1 -1
- package/utils/get-app.js +1 -2
- package/utils/get-compose-x.js +1 -1
- package/utils/get-config-defaults.js +5 -5
- package/utils/get-init-runner-defaults.js +2 -1
- package/utils/parse-events-config.js +21 -1
- package/utils/parse-tooling-config.js +6 -6
- package/utils/to-lando-container.js +16 -2
- package/checksums.txt +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})
|
|
2
2
|
|
|
3
|
-
## v3.23.
|
|
3
|
+
## v3.23.27-1florianPat.0 - [February 17, 2025](https://github.com/florianPat/lando-core/releases/tag/v3.23.27-1florianPat.0)
|
|
4
|
+
|
|
5
|
+
## v3.23.26 - [January 24, 2025](https://github.com/lando/core/releases/tag/v3.23.26)
|
|
6
|
+
|
|
7
|
+
* Fixed bug where an app’s services were inadvertently reaped if the app’s path included a comma [#322](https://github.com/lando/core/issues/322)
|
|
8
|
+
|
|
9
|
+
## v3.23.25 - [January 18, 2025](https://github.com/lando/core/releases/tag/v3.23.25)
|
|
10
|
+
|
|
11
|
+
* Fixed bug causing `--accept-license` flag to not work when installing Docker Desktop on macOS
|
|
12
|
+
* Updated default Docker Desktop version to `4.37.1|2`
|
|
13
|
+
* Updated default Docker Engine version to `27.5.0`
|
|
14
|
+
* Updated default Docker Compose version to `2.31.0`
|
|
15
|
+
* Updated recommended Docker Desktop range to `>=4.37.0`
|
|
16
|
+
* Updated tested Docker Desktop range to `<=4.37`
|
|
17
|
+
* Updated tested Docker Compose range to `<=2.32`
|
|
18
|
+
|
|
19
|
+
## v3.23.24 - [January 14, 2025](https://github.com/lando/core/releases/tag/v3.23.24)
|
|
20
|
+
|
|
21
|
+
* Fixed bug causing service script moving to fail when receiving non-stringy inputs
|
|
22
|
+
|
|
23
|
+
## v3.23.23 - [January 14, 2025](https://github.com/lando/core/releases/tag/v3.23.23)
|
|
24
|
+
|
|
25
|
+
* Fixed bug causing service script loading collisions
|
|
4
26
|
|
|
5
27
|
## v3.23.22 - [December 17, 2024](https://github.com/lando/core/releases/tag/v3.23.22)
|
|
6
28
|
|
package/app.js
CHANGED
|
@@ -240,6 +240,8 @@ module.exports = async (app, lando) => {
|
|
|
240
240
|
BITNAMI_DEBUG: 'true',
|
|
241
241
|
},
|
|
242
242
|
labels: {
|
|
243
|
+
'io.lando.landofiles': app.configFiles.map(file => path.basename(file)).join(','),
|
|
244
|
+
'io.lando.root': app.root,
|
|
243
245
|
'io.lando.src': app.configFiles.join(','),
|
|
244
246
|
'io.lando.http-ports': '80,443',
|
|
245
247
|
},
|
package/builders/_init.js
CHANGED
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
dataHome: null,
|
|
18
18
|
},
|
|
19
19
|
builder: (parent, config) => class LandoInit extends parent {
|
|
20
|
-
constructor(userConfRoot, home, app, env = {}, labels = {}, image = 'devwithlando/util:4') {
|
|
20
|
+
constructor(userConfRoot, home, app, _app, env = {}, labels = {}, image = 'devwithlando/util:4') {
|
|
21
21
|
// Basic Init service
|
|
22
22
|
const initService = {
|
|
23
23
|
services: {
|
|
@@ -36,7 +36,7 @@ module.exports = {
|
|
|
36
36
|
initService.services.init.environment.LANDO_SERVICE_TYPE = 'init';
|
|
37
37
|
initService.services.init.labels['io.lando.service-container'] = 'TRUE';
|
|
38
38
|
initService.services.init.labels['io.lando.init-container'] = 'TRUE';
|
|
39
|
-
super('init', _.merge({}, config, {env, home, labels, userConfRoot}), initService);
|
|
39
|
+
super('init', _.merge({}, config, {env, home, labels, userConfRoot, _app}), initService);
|
|
40
40
|
};
|
|
41
41
|
},
|
|
42
42
|
};
|
package/builders/_lando.js
CHANGED
|
@@ -41,6 +41,7 @@ module.exports = {
|
|
|
41
41
|
refreshCerts = false,
|
|
42
42
|
remoteFiles = {},
|
|
43
43
|
scripts = [],
|
|
44
|
+
scriptsDir = false,
|
|
44
45
|
sport = '443',
|
|
45
46
|
ssl = false,
|
|
46
47
|
sslExpose = true,
|
|
@@ -68,16 +69,25 @@ module.exports = {
|
|
|
68
69
|
console.error(color.yellow(`${type} version ${version} is a legacy version! We recommend upgrading.`));
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// normalize scripts dir if needed
|
|
73
|
+
if (typeof scriptsDir === 'string' && !path.isAbsolute(scriptsDir)) scriptsDir = path.resolve(root, scriptsDir);
|
|
74
|
+
|
|
75
|
+
// Get some basic locations
|
|
76
|
+
const globalScriptsDir = path.join(userConfRoot, 'scripts');
|
|
77
|
+
const serviceScriptsDir = path.join(userConfRoot, 'helpers', project, type, name);
|
|
78
|
+
const entrypointScript = path.join(globalScriptsDir, 'lando-entrypoint.sh');
|
|
79
|
+
const addCertsScript = path.join(globalScriptsDir, 'add-cert.sh');
|
|
80
|
+
const refreshCertsScript = path.join(globalScriptsDir, 'refresh-certs.sh');
|
|
81
|
+
|
|
71
82
|
// Move our config into the userconfroot if we have some
|
|
72
83
|
// NOTE: we need to do this because on macOS and Windows not all host files
|
|
73
84
|
// are shared into the docker vm
|
|
74
85
|
if (fs.existsSync(confSrc)) require('../utils/move-config')(confSrc, confDest);
|
|
75
86
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const refreshCertsScript = path.join(scriptsDir, 'refresh-certs.sh');
|
|
87
|
+
// ditto for service helpers
|
|
88
|
+
if (!require('../utils/is-disabled')(scriptsDir) && typeof scriptsDir === 'string' && fs.existsSync(scriptsDir)) {
|
|
89
|
+
require('../utils/move-config')(scriptsDir, serviceScriptsDir);
|
|
90
|
+
}
|
|
81
91
|
|
|
82
92
|
// Handle Environment
|
|
83
93
|
const environment = {
|
|
@@ -100,10 +110,13 @@ module.exports = {
|
|
|
100
110
|
// Handle volumes
|
|
101
111
|
const volumes = [
|
|
102
112
|
`${userConfRoot}:/lando:cached`,
|
|
103
|
-
`${
|
|
113
|
+
`${globalScriptsDir}:/helpers`,
|
|
104
114
|
`${entrypointScript}:/lando-entrypoint.sh`,
|
|
105
115
|
];
|
|
106
116
|
|
|
117
|
+
// add in service helpers if we have them
|
|
118
|
+
if (fs.existsSync(serviceScriptsDir)) volumes.push(`${serviceScriptsDir}:/etc/lando/service/helpers`);
|
|
119
|
+
|
|
107
120
|
// Handle ssl
|
|
108
121
|
if (ssl) {
|
|
109
122
|
// also expose the sport
|
package/builders/lando-v4.js
CHANGED
|
@@ -443,7 +443,10 @@ module.exports = {
|
|
|
443
443
|
const labels = merge({}, app.labels, {
|
|
444
444
|
'dev.lando.container': 'TRUE',
|
|
445
445
|
'dev.lando.id': lando.config.id,
|
|
446
|
+
'dev.lando.landofiles': app.configFiles.map(file => path.basename(file)).join(','),
|
|
447
|
+
'dev.lando.root': app.root,
|
|
446
448
|
'dev.lando.src': app.root,
|
|
449
|
+
'io.lando.http-ports': '80,443',
|
|
447
450
|
}, config.labels);
|
|
448
451
|
|
|
449
452
|
// add it all 2getha
|
package/config.yml
CHANGED
|
@@ -13,21 +13,21 @@ dockerSupportedVersions:
|
|
|
13
13
|
compose:
|
|
14
14
|
satisfies: "1.x.x || 2.x.x"
|
|
15
15
|
recommendUpdate: "<=2.24.6"
|
|
16
|
-
tested: "<=2.
|
|
16
|
+
tested: "<=2.32.99"
|
|
17
17
|
link:
|
|
18
18
|
linux: https://docs.docker.com/compose/install/#install-compose-on-linux-systems
|
|
19
19
|
darwin: https://docs.docker.com/desktop/install/mac-install/
|
|
20
20
|
win32: https://docs.docker.com/desktop/install/windows-install/
|
|
21
21
|
desktop:
|
|
22
22
|
satisfies: ">=4.0.0 <5"
|
|
23
|
-
tested: "<=4.
|
|
24
|
-
recommendUpdate: "<=4.
|
|
23
|
+
tested: "<=4.37.99"
|
|
24
|
+
recommendUpdate: "<=4.36"
|
|
25
25
|
link:
|
|
26
26
|
darwin: https://docs.docker.com/desktop/install/mac-install/
|
|
27
27
|
win32: https://docs.docker.com/desktop/install/windows-install/
|
|
28
28
|
wsl: https://docs.docker.com/desktop/install/windows-install/
|
|
29
29
|
engine:
|
|
30
30
|
satisfies: ">=18 <28"
|
|
31
|
-
tested: "<=27.
|
|
31
|
+
tested: "<=27.5.99"
|
|
32
32
|
link:
|
|
33
33
|
linux: https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script
|
package/hooks/app-run-events.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const remove = require('../utils/remove');
|
|
5
5
|
const path = require('path');
|
|
6
|
+
const formatters = require('../lib/formatters');
|
|
6
7
|
|
|
7
8
|
module.exports = async (app, lando, cmds, data, event) => {
|
|
8
9
|
const eventCommands = require('./../utils/parse-events-config')(cmds, app, data, lando);
|
|
@@ -29,7 +30,28 @@ module.exports = async (app, lando, cmds, data, event) => {
|
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
const injectable = _.has(app, 'engine') ? app : lando;
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
const splitEventCommands = [];
|
|
35
|
+
while (!_.isEmpty(eventCommands)) {
|
|
36
|
+
splitEventCommands.push(
|
|
37
|
+
_.takeWhile(eventCommands,
|
|
38
|
+
(eventCommand, index) => index === 0 || (!!eventCommand.toolingTask === !!eventCommands[index - 1].toolingTask),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
eventCommands.splice(0, _.last(splitEventCommands).length);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return lando.Promise.mapSeries(splitEventCommands, eventCommands => {
|
|
45
|
+
return lando.Promise.mapSeries(eventCommands, eventCommand => {
|
|
46
|
+
if (undefined !== eventCommand.toolingTask) {
|
|
47
|
+
const inquiry = formatters.getInteractive(eventCommand.toolingTask.options, eventCommand.answers);
|
|
48
|
+
return formatters.handleInteractive(inquiry, eventCommand.answers, eventCommand.toolingTask.command, lando)
|
|
49
|
+
.then(answers => eventCommand.toolingTask.run(_.merge(eventCommand.answers, answers)));
|
|
50
|
+
} else {
|
|
51
|
+
return injectable.engine.run(eventCommands);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}).catch(err => {
|
|
33
55
|
const command = _.tail(event.split('-')).join('-');
|
|
34
56
|
if (app.addMessage) {
|
|
35
57
|
const message = _.trim(_.get(err, 'message')) || 'UNKNOWN ERROR';
|
|
@@ -7,7 +7,7 @@ const path = require('path');
|
|
|
7
7
|
/*
|
|
8
8
|
* Helper to get docker compose v2 download url
|
|
9
9
|
*/
|
|
10
|
-
const getComposeDownloadUrl = (version = '2.
|
|
10
|
+
const getComposeDownloadUrl = (version = '2.31.0') => {
|
|
11
11
|
const mv = version.split('.')[0] > 1 ? '2' : '1';
|
|
12
12
|
const arch = process.arch === 'arm64' ? 'aarch64' : 'x86_64';
|
|
13
13
|
const toggle = `${process.platform}-${mv}`;
|
|
@@ -31,7 +31,7 @@ const getComposeDownloadUrl = (version = '2.30.3') => {
|
|
|
31
31
|
/*
|
|
32
32
|
* Helper to get docker compose v2 download destination
|
|
33
33
|
*/
|
|
34
|
-
const getComposeDownloadDest = (base, version = '2.
|
|
34
|
+
const getComposeDownloadDest = (base, version = '2.31.0') => {
|
|
35
35
|
switch (process.platform) {
|
|
36
36
|
case 'linux':
|
|
37
37
|
case 'darwin':
|
package/lib/app.js
CHANGED
|
@@ -57,7 +57,7 @@ module.exports = class App {
|
|
|
57
57
|
* @alias app.name
|
|
58
58
|
*/
|
|
59
59
|
this.name = require('../utils/slugify')(name);
|
|
60
|
-
this.project =
|
|
60
|
+
this.project = this.name;
|
|
61
61
|
this._serviceApi = 3;
|
|
62
62
|
this._config = lando.config;
|
|
63
63
|
this._defaultService = 'appserver';
|
|
@@ -515,11 +515,11 @@ module.exports = class App {
|
|
|
515
515
|
* Event that only gets triggered if the app never started before (or was destroyed)
|
|
516
516
|
*
|
|
517
517
|
* @since 3.22.3
|
|
518
|
-
* @alias app.events:bootstrap
|
|
519
|
-
* @event bootstrap
|
|
518
|
+
* @alias app.events:pre-bootstrap
|
|
519
|
+
* @event pre-bootstrap
|
|
520
520
|
* @property {App} app The app instance.
|
|
521
521
|
*/
|
|
522
|
-
.then(() => shouldBootstrap ? this.events.emit('bootstrap', this) : undefined)
|
|
522
|
+
.then(() => shouldBootstrap ? this.events.emit('pre-bootstrap', this) : undefined)
|
|
523
523
|
|
|
524
524
|
/**
|
|
525
525
|
* Event that runs before an app starts up.
|
|
@@ -547,6 +547,17 @@ module.exports = class App {
|
|
|
547
547
|
* @event post_start
|
|
548
548
|
*/
|
|
549
549
|
.then(() => this.events.emit('post-start'))
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Event that only gets triggered if the app never started before (or was destroyed)
|
|
553
|
+
*
|
|
554
|
+
* @since 3.22.3
|
|
555
|
+
* @alias app.events:post-bootstrap
|
|
556
|
+
* @event post-bootstrap
|
|
557
|
+
* @property {App} app The app instance.
|
|
558
|
+
*/
|
|
559
|
+
.then(() => shouldBootstrap ? this.events.emit('post-bootstrap', this) : undefined)
|
|
560
|
+
|
|
550
561
|
.then(() => this.log.info('started app.'));
|
|
551
562
|
};
|
|
552
563
|
|
package/lib/daemon.js
CHANGED
|
@@ -53,7 +53,7 @@ module.exports = class LandoDaemon {
|
|
|
53
53
|
log = new Log(),
|
|
54
54
|
context = 'node',
|
|
55
55
|
compose = require('../utils/get-compose-x')(),
|
|
56
|
-
orchestratorVersion = '2.
|
|
56
|
+
orchestratorVersion = '2.31.0',
|
|
57
57
|
userConfRoot = path.join(os.homedir(), '.lando'),
|
|
58
58
|
) {
|
|
59
59
|
this.cache = cache;
|
package/lib/docker.js
CHANGED
|
@@ -92,7 +92,7 @@ module.exports = class Landerode extends Dockerode {
|
|
|
92
92
|
// Filter by app name if an app name was given.
|
|
93
93
|
.then(containers => {
|
|
94
94
|
if (options.project) return _.filter(containers, c => c.app === options.project);
|
|
95
|
-
else if (options.app) return _.filter(containers, c => c.app ===
|
|
95
|
+
else if (options.app) return _.filter(containers, c => c.app === options.app);
|
|
96
96
|
return containers;
|
|
97
97
|
})
|
|
98
98
|
// Then finally filter by everything else
|
package/lib/updates.js
CHANGED
|
@@ -127,7 +127,15 @@ module.exports = class UpdateManager {
|
|
|
127
127
|
const {data, status, url} = await octokit.rest.repos.listReleases({owner: 'lando', repo: 'core'});
|
|
128
128
|
this.debug('retrieved cli information from %o [%o]', url, status);
|
|
129
129
|
|
|
130
|
-
const
|
|
130
|
+
const corePlugin = await this.plugins.find(plugin => plugin.core);
|
|
131
|
+
if (undefined === corePlugin) {
|
|
132
|
+
throw new Error('We should find a core!');
|
|
133
|
+
}
|
|
134
|
+
let newestCoreVersion = corePlugin.check4Update()?.update?.version ?? corePlugin.version;
|
|
135
|
+
if (undefined === newestCoreVersion) {
|
|
136
|
+
throw new Error('Could not obtain the next lando core version!');
|
|
137
|
+
}
|
|
138
|
+
newestCoreVersion = semver.clean(newestCoreVersion);
|
|
131
139
|
|
|
132
140
|
const versions = data
|
|
133
141
|
.map(release => ({...release, version: semver.clean(release.tag_name)}))
|
package/netlify.toml
CHANGED
|
@@ -986,6 +986,57 @@ client.dispatch(
|
|
|
986
986
|
);
|
|
987
987
|
```
|
|
988
988
|
|
|
989
|
+
##### `dns`
|
|
990
|
+
|
|
991
|
+
The `dns` interceptor enables you to cache DNS lookups for a given duration, per origin.
|
|
992
|
+
|
|
993
|
+
>It is well suited for scenarios where you want to cache DNS lookups to avoid the overhead of resolving the same domain multiple times
|
|
994
|
+
|
|
995
|
+
**Options**
|
|
996
|
+
- `maxTTL` - The maximum time-to-live (in milliseconds) of the DNS cache. It should be a positive integer. Default: `10000`.
|
|
997
|
+
- Set `0` to disable TTL.
|
|
998
|
+
- `maxItems` - The maximum number of items to cache. It should be a positive integer. Default: `Infinity`.
|
|
999
|
+
- `dualStack` - Whether to resolve both IPv4 and IPv6 addresses. Default: `true`.
|
|
1000
|
+
- It will also attempt a happy-eyeballs-like approach to connect to the available addresses in case of a connection failure.
|
|
1001
|
+
- `affinity` - Whether to use IPv4 or IPv6 addresses. Default: `4`.
|
|
1002
|
+
- It can be either `'4` or `6`.
|
|
1003
|
+
- It will only take effect if `dualStack` is `false`.
|
|
1004
|
+
- `lookup: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void` - Custom lookup function. Default: `dns.lookup`.
|
|
1005
|
+
- For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
|
|
1006
|
+
- `pick: (origin: URL, records: DNSInterceptorRecords, affinity: 4 | 6) => DNSInterceptorRecord` - Custom pick function. Default: `RoundRobin`.
|
|
1007
|
+
- The function should return a single record from the records array.
|
|
1008
|
+
- By default a simplified version of Round Robin is used.
|
|
1009
|
+
- The `records` property can be mutated to store the state of the balancing algorithm.
|
|
1010
|
+
|
|
1011
|
+
> The `Dispatcher#options` also gets extended with the options `dns.affinity`, `dns.dualStack`, `dns.lookup` and `dns.pick` which can be used to configure the interceptor at a request-per-request basis.
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
**DNSInterceptorRecord**
|
|
1015
|
+
It represents a DNS record.
|
|
1016
|
+
- `family` - (`number`) The IP family of the address. It can be either `4` or `6`.
|
|
1017
|
+
- `address` - (`string`) The IP address.
|
|
1018
|
+
|
|
1019
|
+
**DNSInterceptorOriginRecords**
|
|
1020
|
+
It represents a map of DNS IP addresses records for a single origin.
|
|
1021
|
+
- `4.ips` - (`DNSInterceptorRecord[] | null`) The IPv4 addresses.
|
|
1022
|
+
- `6.ips` - (`DNSInterceptorRecord[] | null`) The IPv6 addresses.
|
|
1023
|
+
|
|
1024
|
+
**Example - Basic DNS Interceptor**
|
|
1025
|
+
|
|
1026
|
+
```js
|
|
1027
|
+
const { Client, interceptors } = require("undici");
|
|
1028
|
+
const { dns } = interceptors;
|
|
1029
|
+
|
|
1030
|
+
const client = new Agent().compose([
|
|
1031
|
+
dns({ ...opts })
|
|
1032
|
+
])
|
|
1033
|
+
|
|
1034
|
+
const response = await client.request({
|
|
1035
|
+
origin: `http://localhost:3030`,
|
|
1036
|
+
...requestOpts
|
|
1037
|
+
})
|
|
1038
|
+
```
|
|
1039
|
+
|
|
989
1040
|
##### `Response Error Interceptor`
|
|
990
1041
|
|
|
991
1042
|
**Introduction**
|
|
@@ -41,7 +41,8 @@ module.exports.createRedirectInterceptor = createRedirectInterceptor
|
|
|
41
41
|
module.exports.interceptors = {
|
|
42
42
|
redirect: require('./lib/interceptor/redirect'),
|
|
43
43
|
retry: require('./lib/interceptor/retry'),
|
|
44
|
-
dump: require('./lib/interceptor/dump')
|
|
44
|
+
dump: require('./lib/interceptor/dump'),
|
|
45
|
+
dns: require('./lib/interceptor/dns')
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
module.exports.buildConnector = buildConnector
|
|
@@ -73,7 +73,7 @@ class RequestHandler extends AsyncResource {
|
|
|
73
73
|
this.removeAbortListener = util.addAbortListener(this.signal, () => {
|
|
74
74
|
this.reason = this.signal.reason ?? new RequestAbortedError()
|
|
75
75
|
if (this.res) {
|
|
76
|
-
util.destroy(this.res, this.reason)
|
|
76
|
+
util.destroy(this.res.on('error', util.nop), this.reason)
|
|
77
77
|
} else if (this.abort) {
|
|
78
78
|
this.abort(this.reason)
|
|
79
79
|
}
|
|
@@ -220,6 +220,11 @@ const setupConnectTimeout = process.platform === 'win32'
|
|
|
220
220
|
* @param {number} opts.port
|
|
221
221
|
*/
|
|
222
222
|
function onConnectTimeout (socket, opts) {
|
|
223
|
+
// The socket could be already garbage collected
|
|
224
|
+
if (socket == null) {
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
223
228
|
let message = 'Connect Timeout Error'
|
|
224
229
|
if (Array.isArray(socket.autoSelectFamilyAttemptedAddresses)) {
|
|
225
230
|
message += ` (attempted addresses: ${socket.autoSelectFamilyAttemptedAddresses.join(', ')},`
|
|
@@ -31,6 +31,8 @@ const {
|
|
|
31
31
|
|
|
32
32
|
const kOpenStreams = Symbol('open streams')
|
|
33
33
|
|
|
34
|
+
let extractBody
|
|
35
|
+
|
|
34
36
|
// Experimental
|
|
35
37
|
let h2ExperimentalWarned = false
|
|
36
38
|
|
|
@@ -240,11 +242,12 @@ function onHTTP2GoAway (code) {
|
|
|
240
242
|
util.destroy(this[kSocket], err)
|
|
241
243
|
|
|
242
244
|
// Fail head of pipeline.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
if (client[kRunningIdx] < client[kQueue].length) {
|
|
246
|
+
const request = client[kQueue][client[kRunningIdx]]
|
|
247
|
+
client[kQueue][client[kRunningIdx]++] = null
|
|
248
|
+
util.errorRequest(client, request, err)
|
|
249
|
+
client[kPendingIdx] = client[kRunningIdx]
|
|
250
|
+
}
|
|
248
251
|
|
|
249
252
|
assert(client[kRunning] === 0)
|
|
250
253
|
|
|
@@ -260,7 +263,8 @@ function shouldSendContentLength (method) {
|
|
|
260
263
|
|
|
261
264
|
function writeH2 (client, request) {
|
|
262
265
|
const session = client[kHTTP2Session]
|
|
263
|
-
const {
|
|
266
|
+
const { method, path, host, upgrade, expectContinue, signal, headers: reqHeaders } = request
|
|
267
|
+
let { body } = request
|
|
264
268
|
|
|
265
269
|
if (upgrade) {
|
|
266
270
|
util.errorRequest(client, request, new Error('Upgrade not supported for H2'))
|
|
@@ -381,6 +385,16 @@ function writeH2 (client, request) {
|
|
|
381
385
|
|
|
382
386
|
let contentLength = util.bodyLength(body)
|
|
383
387
|
|
|
388
|
+
if (util.isFormDataLike(body)) {
|
|
389
|
+
extractBody ??= require('../web/fetch/body.js').extractBody
|
|
390
|
+
|
|
391
|
+
const [bodyStream, contentType] = extractBody(body)
|
|
392
|
+
headers['content-type'] = contentType
|
|
393
|
+
|
|
394
|
+
body = bodyStream.stream
|
|
395
|
+
contentLength = bodyStream.length
|
|
396
|
+
}
|
|
397
|
+
|
|
384
398
|
if (contentLength == null) {
|
|
385
399
|
contentLength = request.contentLength
|
|
386
400
|
}
|
|
@@ -229,7 +229,7 @@ class RetryHandler {
|
|
|
229
229
|
return false
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
const { start, size, end = size } = contentRange
|
|
232
|
+
const { start, size, end = size - 1 } = contentRange
|
|
233
233
|
|
|
234
234
|
assert(this.start === start, 'content-range mismatch')
|
|
235
235
|
assert(this.end == null || this.end === end, 'content-range mismatch')
|
|
@@ -252,7 +252,7 @@ class RetryHandler {
|
|
|
252
252
|
)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
const { start, size, end = size } = range
|
|
255
|
+
const { start, size, end = size - 1 } = range
|
|
256
256
|
assert(
|
|
257
257
|
start != null && Number.isFinite(start),
|
|
258
258
|
'content-range mismatch'
|
|
@@ -266,7 +266,7 @@ class RetryHandler {
|
|
|
266
266
|
// We make our best to checkpoint the body for further range headers
|
|
267
267
|
if (this.end == null) {
|
|
268
268
|
const contentLength = headers['content-length']
|
|
269
|
-
this.end = contentLength != null ? Number(contentLength) : null
|
|
269
|
+
this.end = contentLength != null ? Number(contentLength) - 1 : null
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
assert(Number.isFinite(this.start))
|