@volter/world-core 3.0.120 → 3.0.122
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/dist/inject.cjs +38 -0
- package/inject.cjs +38 -0
- package/package.json +1 -1
package/dist/inject.cjs
CHANGED
|
@@ -780,6 +780,44 @@ async function followKeyless(first, target, reqInit, chain) {
|
|
|
780
780
|
// streaming, aborts and timeouts behave as the client expects); its options are app-route.cjs's, shared with the twins'
|
|
781
781
|
// deliveries.
|
|
782
782
|
function requestApp(route, url, method, headers, extra, callback) {
|
|
783
|
+
if (route.proxy && url.protocol === 'https:') {
|
|
784
|
+
// Some clients inspect the response socket's TLS authorization themselves. CONNECT keeps
|
|
785
|
+
// that a real TLS result while the World proxy still inspects the enclosed HTTP request.
|
|
786
|
+
const agent = new https.Agent({ keepAlive: false });
|
|
787
|
+
const pending = new Set();
|
|
788
|
+
const destroy = agent.destroy.bind(agent);
|
|
789
|
+
agent.destroy = () => { for (const connect of pending) connect.destroy(); pending.clear(); destroy(); };
|
|
790
|
+
agent.createConnection = (options, done) => {
|
|
791
|
+
let settled = false;
|
|
792
|
+
let connected = false;
|
|
793
|
+
const finish = (error, socket) => {
|
|
794
|
+
if (settled) return;
|
|
795
|
+
settled = true; pending.delete(connect);
|
|
796
|
+
done(error, socket);
|
|
797
|
+
};
|
|
798
|
+
const connect = ORIGINALS.httpRequest({ hostname: route.proxy.hostname, port: route.proxy.port || 80,
|
|
799
|
+
method: 'CONNECT', path: `${url.hostname}:${url.port || 443}`, agent: false, timeout: options.timeout });
|
|
800
|
+
pending.add(connect);
|
|
801
|
+
connect.once('error', finish);
|
|
802
|
+
connect.once('close', () => { if (!connected) finish(new Error('World proxy CONNECT closed')); });
|
|
803
|
+
connect.once('timeout', () => connect.destroy(new Error('World proxy CONNECT timed out')));
|
|
804
|
+
connect.once('connect', (response, socket, head) => {
|
|
805
|
+
connected = true;
|
|
806
|
+
if (response.statusCode !== 200) { socket.destroy(); finish(new Error(`World proxy CONNECT answered ${response.statusCode}`)); return; }
|
|
807
|
+
if (head.length) socket.unshift(head);
|
|
808
|
+
try {
|
|
809
|
+
// The existing TLS guard verifies this socket's actual World-proxy peer before allowing its SNI.
|
|
810
|
+
finish(null, tls.connect({ ...options, socket, servername: options.servername || url.hostname }));
|
|
811
|
+
} catch (error) { socket.destroy(); finish(error); }
|
|
812
|
+
});
|
|
813
|
+
connect.end();
|
|
814
|
+
};
|
|
815
|
+
const options = { protocol: 'https:', hostname: url.hostname, port: url.port || 443,
|
|
816
|
+
path: url.pathname + url.search, method, headers: headersForProxy(headers, url), agent, ...extra };
|
|
817
|
+
const request = callback ? ORIGINALS.httpsRequest(options, callback) : ORIGINALS.httpsRequest(options);
|
|
818
|
+
request.once('close', () => agent.destroy());
|
|
819
|
+
return request;
|
|
820
|
+
}
|
|
783
821
|
const options = route.proxy
|
|
784
822
|
? { protocol: 'http:', hostname: route.proxy.hostname, port: route.proxy.port, path: url.href, method,
|
|
785
823
|
headers: headersForProxy(headers, url), agent: false, ...extra }
|
package/inject.cjs
CHANGED
|
@@ -780,6 +780,44 @@ async function followKeyless(first, target, reqInit, chain) {
|
|
|
780
780
|
// streaming, aborts and timeouts behave as the client expects); its options are app-route.cjs's, shared with the twins'
|
|
781
781
|
// deliveries.
|
|
782
782
|
function requestApp(route, url, method, headers, extra, callback) {
|
|
783
|
+
if (route.proxy && url.protocol === 'https:') {
|
|
784
|
+
// Some clients inspect the response socket's TLS authorization themselves. CONNECT keeps
|
|
785
|
+
// that a real TLS result while the World proxy still inspects the enclosed HTTP request.
|
|
786
|
+
const agent = new https.Agent({ keepAlive: false });
|
|
787
|
+
const pending = new Set();
|
|
788
|
+
const destroy = agent.destroy.bind(agent);
|
|
789
|
+
agent.destroy = () => { for (const connect of pending) connect.destroy(); pending.clear(); destroy(); };
|
|
790
|
+
agent.createConnection = (options, done) => {
|
|
791
|
+
let settled = false;
|
|
792
|
+
let connected = false;
|
|
793
|
+
const finish = (error, socket) => {
|
|
794
|
+
if (settled) return;
|
|
795
|
+
settled = true; pending.delete(connect);
|
|
796
|
+
done(error, socket);
|
|
797
|
+
};
|
|
798
|
+
const connect = ORIGINALS.httpRequest({ hostname: route.proxy.hostname, port: route.proxy.port || 80,
|
|
799
|
+
method: 'CONNECT', path: `${url.hostname}:${url.port || 443}`, agent: false, timeout: options.timeout });
|
|
800
|
+
pending.add(connect);
|
|
801
|
+
connect.once('error', finish);
|
|
802
|
+
connect.once('close', () => { if (!connected) finish(new Error('World proxy CONNECT closed')); });
|
|
803
|
+
connect.once('timeout', () => connect.destroy(new Error('World proxy CONNECT timed out')));
|
|
804
|
+
connect.once('connect', (response, socket, head) => {
|
|
805
|
+
connected = true;
|
|
806
|
+
if (response.statusCode !== 200) { socket.destroy(); finish(new Error(`World proxy CONNECT answered ${response.statusCode}`)); return; }
|
|
807
|
+
if (head.length) socket.unshift(head);
|
|
808
|
+
try {
|
|
809
|
+
// The existing TLS guard verifies this socket's actual World-proxy peer before allowing its SNI.
|
|
810
|
+
finish(null, tls.connect({ ...options, socket, servername: options.servername || url.hostname }));
|
|
811
|
+
} catch (error) { socket.destroy(); finish(error); }
|
|
812
|
+
});
|
|
813
|
+
connect.end();
|
|
814
|
+
};
|
|
815
|
+
const options = { protocol: 'https:', hostname: url.hostname, port: url.port || 443,
|
|
816
|
+
path: url.pathname + url.search, method, headers: headersForProxy(headers, url), agent, ...extra };
|
|
817
|
+
const request = callback ? ORIGINALS.httpsRequest(options, callback) : ORIGINALS.httpsRequest(options);
|
|
818
|
+
request.once('close', () => agent.destroy());
|
|
819
|
+
return request;
|
|
820
|
+
}
|
|
783
821
|
const options = route.proxy
|
|
784
822
|
? { protocol: 'http:', hostname: route.proxy.hostname, port: route.proxy.port, path: url.href, method,
|
|
785
823
|
headers: headersForProxy(headers, url), agent: false, ...extra }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/world-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.122",
|
|
4
4
|
"description": "The kernel of Volter World: one log per twin, branches as pointers, checkpoints, the fold that keeps a twin current, the head that performs a write against the vendor, references, and the git plane. A twin package builds on it; the runtime serves it.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"twin",
|