@stryke/http 0.12.13 → 0.12.15
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 +14 -0
- package/dist/{chunk-Bmb41Sf3.cjs → _virtual/rolldown_runtime.cjs} +1 -1
- package/dist/agent.cjs +2 -1
- package/dist/agent.d.cts +40 -2
- package/dist/agent.d.cts.map +1 -0
- package/dist/agent.d.mts +40 -2
- package/dist/agent.d.mts.map +1 -0
- package/dist/agent.mjs +3 -1
- package/dist/agent.mjs.map +1 -0
- package/dist/fetch.cjs +1 -1
- package/dist/fetch.d.cts +24 -2
- package/dist/fetch.d.cts.map +1 -0
- package/dist/fetch.d.mts +24 -2
- package/dist/fetch.d.mts.map +1 -0
- package/dist/fetch.mjs +2 -1
- package/dist/fetch.mjs.map +1 -0
- package/dist/format-data-uri.cjs +1 -1
- package/dist/format-data-uri.d.cts +50 -2
- package/dist/format-data-uri.d.cts.map +1 -0
- package/dist/format-data-uri.d.mts +50 -2
- package/dist/format-data-uri.d.mts.map +1 -0
- package/dist/format-data-uri.mjs +2 -1
- package/dist/format-data-uri.mjs.map +1 -0
- package/dist/get-free-port.cjs +1 -1
- package/dist/get-free-port.d.cts +10 -2
- package/dist/get-free-port.d.cts.map +1 -0
- package/dist/get-free-port.d.mts +10 -2
- package/dist/get-free-port.d.mts.map +1 -0
- package/dist/get-free-port.mjs +2 -1
- package/dist/get-free-port.mjs.map +1 -0
- package/dist/http-proxy.cjs +3 -1
- package/dist/http-proxy.d.cts +40 -2
- package/dist/http-proxy.d.cts.map +1 -0
- package/dist/http-proxy.d.mts +40 -2
- package/dist/http-proxy.d.mts.map +1 -0
- package/dist/http-proxy.mjs +4 -1
- package/dist/http-proxy.mjs.map +1 -0
- package/dist/https-proxy.cjs +1 -1
- package/dist/https-proxy.d.cts +43 -2
- package/dist/https-proxy.d.cts.map +1 -0
- package/dist/https-proxy.d.mts +43 -2
- package/dist/https-proxy.d.mts.map +1 -0
- package/dist/https-proxy.mjs +2 -1
- package/dist/https-proxy.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +1 -1
- package/dist/parse-response.cjs +4 -1
- package/dist/parse-response.d.cts +23 -2
- package/dist/parse-response.d.cts.map +1 -0
- package/dist/parse-response.d.mts +23 -2
- package/dist/parse-response.d.mts.map +1 -0
- package/dist/parse-response.mjs +5 -1
- package/dist/parse-response.mjs.map +1 -0
- package/dist/proxy-agent.cjs +1 -1
- package/dist/proxy-agent.d.cts +13 -2
- package/dist/proxy-agent.d.cts.map +1 -0
- package/dist/proxy-agent.d.mts +13 -2
- package/dist/proxy-agent.d.mts.map +1 -0
- package/dist/proxy-agent.mjs +2 -1
- package/dist/proxy-agent.mjs.map +1 -0
- package/dist/type-checks/src/index.cjs +1 -0
- package/dist/type-checks/src/index.mjs +1 -0
- package/dist/type-checks/src/is-boolean.cjs +1 -0
- package/dist/type-checks/src/is-boolean.mjs +2 -0
- package/dist/type-checks/src/is-boolean.mjs.map +1 -0
- package/dist/type-checks/src/is-buffer.cjs +1 -0
- package/dist/type-checks/src/is-buffer.mjs +2 -0
- package/dist/type-checks/src/is-buffer.mjs.map +1 -0
- package/dist/type-checks/src/is-collection.cjs +1 -0
- package/dist/type-checks/src/is-collection.mjs +1 -0
- package/dist/type-checks/src/is-empty.cjs +1 -0
- package/dist/type-checks/src/is-empty.mjs +2 -0
- package/dist/type-checks/src/is-empty.mjs.map +1 -0
- package/dist/type-checks/src/is-null.cjs +1 -0
- package/dist/type-checks/src/is-null.mjs +2 -0
- package/dist/type-checks/src/is-null.mjs.map +1 -0
- package/dist/type-checks/src/is-set-string.cjs +1 -0
- package/dist/type-checks/src/is-set-string.mjs +2 -0
- package/dist/type-checks/src/is-set-string.mjs.map +1 -0
- package/dist/type-checks/src/is-set.cjs +1 -0
- package/dist/type-checks/src/is-set.mjs +2 -0
- package/dist/type-checks/src/is-set.mjs.map +1 -0
- package/dist/type-checks/src/is-string.cjs +1 -0
- package/dist/type-checks/src/is-string.mjs +2 -0
- package/dist/type-checks/src/is-string.mjs.map +1 -0
- package/dist/type-checks/src/is-undefined.cjs +1 -0
- package/dist/type-checks/src/is-undefined.mjs +2 -0
- package/dist/type-checks/src/is-undefined.mjs.map +1 -0
- package/dist/type-checks/src/type-detect.cjs +1 -0
- package/dist/type-checks/src/type-detect.mjs +2 -0
- package/dist/type-checks/src/type-detect.mjs.map +1 -0
- package/dist/url/src/helpers.cjs +1 -0
- package/dist/url/src/helpers.mjs +2 -0
- package/dist/url/src/helpers.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/agent-Cc4PYJ-j.d.cts +0 -40
- package/dist/agent-Cc4PYJ-j.d.cts.map +0 -1
- package/dist/agent-DKevd8Ll.cjs +0 -2
- package/dist/agent-DXIpD4O5.d.mts +0 -40
- package/dist/agent-DXIpD4O5.d.mts.map +0 -1
- package/dist/agent-DrFvt4od.mjs +0 -3
- package/dist/agent-DrFvt4od.mjs.map +0 -1
- package/dist/fetch-BYPFJG9Y.d.cts +0 -24
- package/dist/fetch-BYPFJG9Y.d.cts.map +0 -1
- package/dist/fetch-D3masEhH.d.mts +0 -24
- package/dist/fetch-D3masEhH.d.mts.map +0 -1
- package/dist/fetch-DXVSCX2B.cjs +0 -1
- package/dist/fetch-DgPaAZTB.mjs +0 -2
- package/dist/fetch-DgPaAZTB.mjs.map +0 -1
- package/dist/format-data-uri-B-rw3THu.d.cts +0 -50
- package/dist/format-data-uri-B-rw3THu.d.cts.map +0 -1
- package/dist/format-data-uri-C59EgrXn.cjs +0 -1
- package/dist/format-data-uri-D864kwXt.d.mts +0 -50
- package/dist/format-data-uri-D864kwXt.d.mts.map +0 -1
- package/dist/format-data-uri-WSwfftd0.mjs +0 -2
- package/dist/format-data-uri-WSwfftd0.mjs.map +0 -1
- package/dist/get-free-port-Bf-x1nt8.d.cts +0 -10
- package/dist/get-free-port-Bf-x1nt8.d.cts.map +0 -1
- package/dist/get-free-port-BwvXPXFs.d.mts +0 -10
- package/dist/get-free-port-BwvXPXFs.d.mts.map +0 -1
- package/dist/get-free-port-D9hjek4b.cjs +0 -1
- package/dist/get-free-port-DvWNGhhy.mjs +0 -2
- package/dist/get-free-port-DvWNGhhy.mjs.map +0 -1
- package/dist/http-proxy-CJqbqeZN.cjs +0 -3
- package/dist/http-proxy-ChUYEQ71.mjs +0 -4
- package/dist/http-proxy-ChUYEQ71.mjs.map +0 -1
- package/dist/http-proxy-CzvOBKWd.d.cts +0 -40
- package/dist/http-proxy-CzvOBKWd.d.cts.map +0 -1
- package/dist/http-proxy-DuPPyvFw.d.mts +0 -40
- package/dist/http-proxy-DuPPyvFw.d.mts.map +0 -1
- package/dist/https-proxy-B8w-jm17.d.cts +0 -43
- package/dist/https-proxy-B8w-jm17.d.cts.map +0 -1
- package/dist/https-proxy-f4-C_EL8.d.mts +0 -43
- package/dist/https-proxy-f4-C_EL8.d.mts.map +0 -1
- package/dist/https-proxy-k0GW_xX8.cjs +0 -1
- package/dist/https-proxy-rNc_8MiC.mjs +0 -2
- package/dist/https-proxy-rNc_8MiC.mjs.map +0 -1
- package/dist/parse-response-BRlQF_8K.cjs +0 -4
- package/dist/parse-response-CGkjN9j0.mjs +0 -5
- package/dist/parse-response-CGkjN9j0.mjs.map +0 -1
- package/dist/parse-response-CS657Hki.d.cts +0 -23
- package/dist/parse-response-CS657Hki.d.cts.map +0 -1
- package/dist/parse-response-ujHVHmwG.d.mts +0 -23
- package/dist/parse-response-ujHVHmwG.d.mts.map +0 -1
- package/dist/proxy-agent-BrxQeFy2.d.mts +0 -13
- package/dist/proxy-agent-BrxQeFy2.d.mts.map +0 -1
- package/dist/proxy-agent-CnWrJ59l.d.cts +0 -13
- package/dist/proxy-agent-CnWrJ59l.d.cts.map +0 -1
- package/dist/proxy-agent-DMsOloiQ.cjs +0 -1
- package/dist/proxy-agent-uGI03t_I.mjs +0 -2
- package/dist/proxy-agent-uGI03t_I.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - HTTP
|
|
4
4
|
|
|
5
|
+
## [0.12.14](https://github.com/storm-software/stryke/releases/tag/http%400.12.14) (12/08/2025)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **type-checks** to **v0.5.9**
|
|
10
|
+
- Updated **url** to **v0.3.15**
|
|
11
|
+
|
|
12
|
+
## [0.12.13](https://github.com/storm-software/stryke/releases/tag/http%400.12.13) (12/08/2025)
|
|
13
|
+
|
|
14
|
+
### Updated Dependencies
|
|
15
|
+
|
|
16
|
+
- Updated **type-checks** to **v0.5.8**
|
|
17
|
+
- Updated **url** to **v0.3.14**
|
|
18
|
+
|
|
5
19
|
## [0.12.12](https://github.com/storm-software/stryke/releases/tag/http%400.12.12) (12/08/2025)
|
|
6
20
|
|
|
7
21
|
### Updated Dependencies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
|
package/dist/agent.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-boolean.cjs`),n=require(`./type-checks/src/is-string.cjs`);require(`./type-checks/src/index.cjs`);let r=require(`node:http`);r=e.__toESM(r);let i=require(`node:net`);i=e.__toESM(i);const a=Symbol(`Agent`);var o=class extends r.Agent{[a];options;keepAlive;constructor(e){super(e),this[a]={}}isSecureEndpoint(e){if(e){if(t.isBoolean(e.secureEndpoint))return e.secureEndpoint;if(n.isString(e.protocol))return e.protocol===`https:`}let{stack:r}=Error(` `);return n.isString(r)?r.split(`
|
|
2
|
+
`).some(e=>e.includes(`(https.js:`)||e.includes(`node:https:`)):!1}incrementSockets(e){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;this.sockets[e]??=[];let t=new i.Socket({writable:!1});return this.sockets[e].push(t),this.totalSocketCount++,t}decrementSockets(e,t){if(!this.sockets[e]||t===null)return;let n=this.sockets[e],r=n.indexOf(t);r!==-1&&(n.splice(r,1),this.totalSocketCount--,n.length===0&&delete this.sockets[e])}getName(e){return this.isSecureEndpoint(e)?HttpsAgent.prototype.getName.call(this,e):super.getName(e)}createSocket(e,t,n){let i={...t,secureEndpoint:this.isSecureEndpoint(t)},o=this.getName(i),s=this.incrementSockets(o);Promise.resolve().then(async()=>this.connect(e,i)).then(c=>{if(this.decrementSockets(o,s),c instanceof r.Agent)try{return c.addRequest(e,i)}catch(e){return n(e)}this[a].currentSocket=c,super.createSocket(e,t,n)},e=>{this.decrementSockets(o,s),n(e)})}createConnection(){let e=this[a].currentSocket;if(this[a].currentSocket=void 0,!e)throw Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return this[a].defaultPort??(this.protocol===`https:`?443:80)}set defaultPort(e){this[a]&&(this[a].defaultPort=e)}get protocol(){return this[a].protocol??(this.isSecureEndpoint()?`https:`:`http:`)}set protocol(e){this[a]&&(this[a].protocol=e)}};exports.Agent=o;
|
package/dist/agent.d.cts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import * as net from "node:net";
|
|
3
|
+
import { Duplex } from "node:stream";
|
|
4
|
+
import * as tls from "node:tls";
|
|
5
|
+
|
|
6
|
+
//#region src/agent.d.ts
|
|
7
|
+
interface HttpConnectOpts extends net.TcpNetConnectOpts {
|
|
8
|
+
secureEndpoint: false;
|
|
9
|
+
protocol?: string;
|
|
10
|
+
}
|
|
11
|
+
interface HttpsConnectOpts extends tls.ConnectionOptions {
|
|
12
|
+
secureEndpoint: true;
|
|
13
|
+
protocol?: string;
|
|
14
|
+
port: number;
|
|
15
|
+
}
|
|
16
|
+
type AgentConnectOpts = HttpConnectOpts | HttpsConnectOpts;
|
|
17
|
+
declare const SYMBOL_INTERNAL: unique symbol;
|
|
18
|
+
declare abstract class Agent extends http.Agent {
|
|
19
|
+
private [SYMBOL_INTERNAL];
|
|
20
|
+
options: Partial<net.TcpNetConnectOpts & tls.ConnectionOptions>;
|
|
21
|
+
keepAlive: boolean;
|
|
22
|
+
constructor(opts?: http.AgentOptions);
|
|
23
|
+
abstract connect(req: http.ClientRequest, options: AgentConnectOpts): Promise<Duplex | http.Agent> | Duplex | http.Agent;
|
|
24
|
+
/**
|
|
25
|
+
* Determine whether this is an `http` or `https` request.
|
|
26
|
+
*/
|
|
27
|
+
isSecureEndpoint(options?: AgentConnectOpts): boolean;
|
|
28
|
+
private incrementSockets;
|
|
29
|
+
private decrementSockets;
|
|
30
|
+
getName(options?: AgentConnectOpts): string;
|
|
31
|
+
createSocket(req: http.ClientRequest, options: AgentConnectOpts, cb: (err: Error | null, s?: Duplex) => void): void;
|
|
32
|
+
createConnection(): Duplex;
|
|
33
|
+
get defaultPort(): number;
|
|
34
|
+
set defaultPort(v: number);
|
|
35
|
+
get protocol(): string;
|
|
36
|
+
set protocol(v: string);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Agent, AgentConnectOpts };
|
|
40
|
+
//# sourceMappingURL=agent.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.cts","names":[],"sources":["../src/agent.ts"],"sourcesContent":[],"mappings":";;;;;;UAyBU,eAAA,SAAwB,GAAA,CAAI;;EAA5B,QAAA,CAAA,EAAA,MAAA;AAA6C;AAWvD,UANU,gBAAA,SAAyB,GAAA,CAAI,iBAMU,CAAA;EAE3C,cAAA,EAAA,IAAiC;EAQjB,QAAM,CAAA,EAAA,MAAA;EACjB,IAAA,EAAA,MAAA;;AAGqC,KAdpC,gBAAA,GAAmB,eAciB,GAdC,gBAcD;cAZ1C,eAYM,EAAA,OAAA,MAAA;AAIc,uBARJ,KAAA,SAAc,IAAA,CAAK,KAAA,CAQf;EAMjB,SAbE,eAAA;EAcE,OAAA,EAXD,OAWC,CAXO,GAAA,CAAI,iBAWX,GAX+B,GAAA,CAAI,iBAWnC,CAAA;EACA,SAAA,EAAA,OAAA;EAAS,WAAK,CAAA,IAAA,CAAA,EARN,IAAA,CAAK,YAQC;EAAtB,SAAA,OAAA,CAAA,GAAA,EAFI,IAAA,CAAK,aAET,EAAA,OAAA,EADQ,gBACR,CAAA,EAAA,OAAA,CAAQ,MAAR,GAAiB,IAAA,CAAK,KAAtB,CAAA,GAA+B,MAA/B,GAAwC,IAAA,CAAK,KAA7C;EAA+B;;;EAgFP,gBAAA,CAAA,OAAA,CAAA,EA3EA,gBA2EA,CAAA,EAAA,OAAA;EAWpB,QAAK,gBAAA;EACD,QAAA,gBAAA;EACC,OAAA,CAAA,OAAA,CAAA,EAbe,gBAaf,CAAA,EAAA,MAAA;EAAkB,YAAA,CAAA,GAAA,EAFvB,IAAA,CAAK,aAEkB,EAAA,OAAA,EADnB,gBACmB,EAAA,EAAA,EAAA,CAAA,GAAA,EAAlB,KAAkB,GAAA,IAAA,EAAA,CAAA,CAAA,EAAA,MAAA,EAAA,GAAA,IAAA,CAAA,EAAA,IAAA;EAkCD,gBAAA,CAAA,CAAA,EAAA,MAAA;EA/IK,IAAK,WAAA,CAAA,CAAA,EAAA,MAAA;EAAK,IAAA,WAAA,CAAA,CAAA,EAAA,MAAA"}
|
package/dist/agent.d.mts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import * as net from "node:net";
|
|
3
|
+
import * as tls from "node:tls";
|
|
4
|
+
import { Duplex } from "node:stream";
|
|
5
|
+
|
|
6
|
+
//#region src/agent.d.ts
|
|
7
|
+
interface HttpConnectOpts extends net.TcpNetConnectOpts {
|
|
8
|
+
secureEndpoint: false;
|
|
9
|
+
protocol?: string;
|
|
10
|
+
}
|
|
11
|
+
interface HttpsConnectOpts extends tls.ConnectionOptions {
|
|
12
|
+
secureEndpoint: true;
|
|
13
|
+
protocol?: string;
|
|
14
|
+
port: number;
|
|
15
|
+
}
|
|
16
|
+
type AgentConnectOpts = HttpConnectOpts | HttpsConnectOpts;
|
|
17
|
+
declare const SYMBOL_INTERNAL: unique symbol;
|
|
18
|
+
declare abstract class Agent extends http.Agent {
|
|
19
|
+
private [SYMBOL_INTERNAL];
|
|
20
|
+
options: Partial<net.TcpNetConnectOpts & tls.ConnectionOptions>;
|
|
21
|
+
keepAlive: boolean;
|
|
22
|
+
constructor(opts?: http.AgentOptions);
|
|
23
|
+
abstract connect(req: http.ClientRequest, options: AgentConnectOpts): Promise<Duplex | http.Agent> | Duplex | http.Agent;
|
|
24
|
+
/**
|
|
25
|
+
* Determine whether this is an `http` or `https` request.
|
|
26
|
+
*/
|
|
27
|
+
isSecureEndpoint(options?: AgentConnectOpts): boolean;
|
|
28
|
+
private incrementSockets;
|
|
29
|
+
private decrementSockets;
|
|
30
|
+
getName(options?: AgentConnectOpts): string;
|
|
31
|
+
createSocket(req: http.ClientRequest, options: AgentConnectOpts, cb: (err: Error | null, s?: Duplex) => void): void;
|
|
32
|
+
createConnection(): Duplex;
|
|
33
|
+
get defaultPort(): number;
|
|
34
|
+
set defaultPort(v: number);
|
|
35
|
+
get protocol(): string;
|
|
36
|
+
set protocol(v: string);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Agent, AgentConnectOpts };
|
|
40
|
+
//# sourceMappingURL=agent.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.mts","names":[],"sources":["../src/agent.ts"],"sourcesContent":[],"mappings":";;;;;;UAyBU,eAAA,SAAwB,GAAA,CAAI;;EAA5B,QAAA,CAAA,EAAA,MAAA;AAA6C;AAWvD,UANU,gBAAA,SAAyB,GAAA,CAAI,iBAMU,CAAA;EAE3C,cAAA,EAAA,IAAiC;EAQjB,QAAM,CAAA,EAAA,MAAA;EACjB,IAAA,EAAA,MAAA;;AAGqC,KAdpC,gBAAA,GAAmB,eAciB,GAdC,gBAcD;cAZ1C,eAYM,EAAA,OAAA,MAAA;AAIc,uBARJ,KAAA,SAAc,IAAA,CAAK,KAAA,CAQf;EAMjB,SAbE,eAAA;EAcE,OAAA,EAXD,OAWC,CAXO,GAAA,CAAI,iBAWX,GAX+B,GAAA,CAAI,iBAWnC,CAAA;EACA,SAAA,EAAA,OAAA;EAAS,WAAK,CAAA,IAAA,CAAA,EARN,IAAA,CAAK,YAQC;EAAtB,SAAA,OAAA,CAAA,GAAA,EAFI,IAAA,CAAK,aAET,EAAA,OAAA,EADQ,gBACR,CAAA,EAAA,OAAA,CAAQ,MAAR,GAAiB,IAAA,CAAK,KAAtB,CAAA,GAA+B,MAA/B,GAAwC,IAAA,CAAK,KAA7C;EAA+B;;;EAgFP,gBAAA,CAAA,OAAA,CAAA,EA3EA,gBA2EA,CAAA,EAAA,OAAA;EAWpB,QAAK,gBAAA;EACD,QAAA,gBAAA;EACC,OAAA,CAAA,OAAA,CAAA,EAbe,gBAaf,CAAA,EAAA,MAAA;EAAkB,YAAA,CAAA,GAAA,EAFvB,IAAA,CAAK,aAEkB,EAAA,OAAA,EADnB,gBACmB,EAAA,EAAA,EAAA,CAAA,GAAA,EAAlB,KAAkB,GAAA,IAAA,EAAA,CAAA,CAAA,EAAA,MAAA,EAAA,GAAA,IAAA,CAAA,EAAA,IAAA;EAkCD,gBAAA,CAAA,CAAA,EAAA,MAAA;EA/IK,IAAK,WAAA,CAAA,CAAA,EAAA,MAAA;EAAK,IAAA,WAAA,CAAA,CAAA,EAAA,MAAA"}
|
package/dist/agent.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isBoolean as e}from"./type-checks/src/is-boolean.mjs";import{isString as t}from"./type-checks/src/is-string.mjs";import"./type-checks/src/index.mjs";import*as n from"node:http";import*as r from"node:net";const i=Symbol(`Agent`);var a=class extends n.Agent{[i];options;keepAlive;constructor(e){super(e),this[i]={}}isSecureEndpoint(n){if(n){if(e(n.secureEndpoint))return n.secureEndpoint;if(t(n.protocol))return n.protocol===`https:`}let{stack:r}=Error(` `);return t(r)?r.split(`
|
|
2
|
+
`).some(e=>e.includes(`(https.js:`)||e.includes(`node:https:`)):!1}incrementSockets(e){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;this.sockets[e]??=[];let t=new r.Socket({writable:!1});return this.sockets[e].push(t),this.totalSocketCount++,t}decrementSockets(e,t){if(!this.sockets[e]||t===null)return;let n=this.sockets[e],r=n.indexOf(t);r!==-1&&(n.splice(r,1),this.totalSocketCount--,n.length===0&&delete this.sockets[e])}getName(e){return this.isSecureEndpoint(e)?HttpsAgent.prototype.getName.call(this,e):super.getName(e)}createSocket(e,t,r){let a={...t,secureEndpoint:this.isSecureEndpoint(t)},o=this.getName(a),s=this.incrementSockets(o);Promise.resolve().then(async()=>this.connect(e,a)).then(c=>{if(this.decrementSockets(o,s),c instanceof n.Agent)try{return c.addRequest(e,a)}catch(e){return r(e)}this[i].currentSocket=c,super.createSocket(e,t,r)},e=>{this.decrementSockets(o,s),r(e)})}createConnection(){let e=this[i].currentSocket;if(this[i].currentSocket=void 0,!e)throw Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return this[i].defaultPort??(this.protocol===`https:`?443:80)}set defaultPort(e){this[i]&&(this[i].defaultPort=e)}get protocol(){return this[i].protocol??(this.isSecureEndpoint()?`https:`:`http:`)}set protocol(e){this[i]&&(this[i].protocol=e)}};export{a as Agent};
|
|
3
|
+
//# sourceMappingURL=agent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.mjs","names":["err: unknown"],"sources":["../src/agent.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isBoolean, isString } from \"@stryke/type-checks\";\nimport * as http from \"node:http\";\nimport type { Agent as HttpsAgent } from \"node:https\";\nimport * as net from \"node:net\";\nimport type { Duplex } from \"node:stream\";\nimport type * as tls from \"node:tls\";\n\ninterface HttpConnectOpts extends net.TcpNetConnectOpts {\n secureEndpoint: false;\n protocol?: string;\n}\n\ninterface HttpsConnectOpts extends tls.ConnectionOptions {\n secureEndpoint: true;\n protocol?: string;\n port: number;\n}\n\nexport type AgentConnectOpts = HttpConnectOpts | HttpsConnectOpts;\n\nconst SYMBOL_INTERNAL = Symbol(\"Agent\");\n\ninterface InternalState {\n defaultPort?: number;\n protocol?: string;\n currentSocket?: Duplex;\n}\n\nexport abstract class Agent extends http.Agent {\n private [SYMBOL_INTERNAL]: InternalState;\n\n // Set by `http.Agent` - missing from `@types/node`\n options!: Partial<net.TcpNetConnectOpts & tls.ConnectionOptions>;\n\n keepAlive!: boolean;\n\n constructor(opts?: http.AgentOptions) {\n super(opts);\n this[SYMBOL_INTERNAL] = {};\n }\n\n abstract connect(\n req: http.ClientRequest,\n options: AgentConnectOpts\n ): Promise<Duplex | http.Agent> | Duplex | http.Agent;\n\n /**\n * Determine whether this is an `http` or `https` request.\n */\n isSecureEndpoint(options?: AgentConnectOpts): boolean {\n if (options) {\n // First check the `secureEndpoint` property explicitly, since this\n // means that a parent `Agent` is \"passing through\" to this instance.\n if (isBoolean((options as any).secureEndpoint)) {\n return options.secureEndpoint;\n }\n\n // If no explicit `secure` endpoint, check if `protocol` property is\n // set. This will usually be the case since using a full string URL\n // or `URL` instance should be the most common usage.\n if (isString(options.protocol)) {\n return options.protocol === \"https:\";\n }\n }\n\n // Finally, if no `protocol` property was set, then fall back to\n // checking the stack trace of the current call stack, and try to\n // detect the \"https\" module.\n const { stack } = new Error(\" \");\n if (!isString(stack)) {\n return false;\n }\n\n return stack\n .split(\"\\n\")\n .some(l => l.includes(\"(https.js:\") || l.includes(\"node:https:\"));\n }\n\n // In order to support async signatures in `connect()` and Node's native\n // connection pooling in `http.Agent`, the array of sockets for each origin\n // has to be updated synchronously. This is so the length of the array is\n // accurate when `addRequest()` is next called. We achieve this by creating a\n // fake socket and adding it to `sockets[origin]` and incrementing\n // `totalSocketCount`.\n private incrementSockets(name: string) {\n // If `maxSockets` and `maxTotalSockets` are both Infinity then there is no\n // need to create a fake socket because Node.js native connection pooling\n // will never be invoked.\n if (this.maxSockets === Infinity && this.maxTotalSockets === Infinity) {\n return null;\n }\n // All instances of `sockets` are expected TypeScript errors. The\n // alternative is to add it as a private property of this class but that\n // will break TypeScript sub-classing.\n\n // @ts-expect-error `sockets` is readonly in `@types/node`\n this.sockets[name] ??= [];\n\n const fakeSocket = new net.Socket({ writable: false });\n this.sockets[name].push(fakeSocket);\n // @ts-expect-error `totalSocketCount` isn't defined in `@types/node`\n this.totalSocketCount++;\n return fakeSocket;\n }\n\n private decrementSockets(name: string, socket: null | net.Socket) {\n if (!this.sockets[name] || socket === null) {\n return;\n }\n const sockets = this.sockets[name];\n const index = sockets.indexOf(socket);\n if (index !== -1) {\n sockets.splice(index, 1);\n // @ts-expect-error `totalSocketCount` isn't defined in `@types/node`\n this.totalSocketCount--;\n if (sockets.length === 0) {\n // @ts-expect-error `sockets` is readonly in `@types/node`\n delete this.sockets[name];\n }\n }\n }\n\n // In order to properly update the socket pool, we need to call `getName()` on\n // the core `https.Agent` if it is a secureEndpoint.\n override getName(options?: AgentConnectOpts): string {\n const secureEndpoint = this.isSecureEndpoint(options);\n if (secureEndpoint) {\n // @ts-expect-error `getName()` isn't defined in `@types/node`\n return HttpsAgent.prototype.getName.call(this, options);\n }\n\n return super.getName(options);\n }\n\n createSocket(\n req: http.ClientRequest,\n options: AgentConnectOpts,\n cb: (err: Error | null, s?: Duplex) => void\n ) {\n const connectOpts = {\n ...options,\n secureEndpoint: this.isSecureEndpoint(options)\n };\n const name = this.getName(connectOpts);\n const fakeSocket = this.incrementSockets(name);\n Promise.resolve()\n .then(async () => this.connect(req, connectOpts))\n .then(\n socket => {\n this.decrementSockets(name, fakeSocket);\n if (socket instanceof http.Agent) {\n try {\n // @ts-expect-error `addRequest()` isn't defined in `@types/node`\n // eslint-disable-next-line ts/no-unsafe-call\n return socket.addRequest(req, connectOpts);\n } catch (err: unknown) {\n return cb(err as Error);\n }\n }\n this[SYMBOL_INTERNAL].currentSocket = socket;\n // @ts-expect-error `createSocket()` isn't defined in `@types/node`\n // eslint-disable-next-line ts/no-unsafe-call\n super.createSocket(req, options, cb);\n },\n err => {\n this.decrementSockets(name, fakeSocket);\n cb(err);\n }\n );\n }\n\n override createConnection(): Duplex {\n const socket = this[SYMBOL_INTERNAL].currentSocket;\n this[SYMBOL_INTERNAL].currentSocket = undefined;\n if (!socket) {\n throw new Error(\"No socket was returned in the `connect()` function\");\n }\n return socket;\n }\n\n get defaultPort(): number {\n return (\n this[SYMBOL_INTERNAL].defaultPort ??\n (this.protocol === \"https:\" ? 443 : 80)\n );\n }\n\n set defaultPort(v: number) {\n if (this[SYMBOL_INTERNAL]) {\n this[SYMBOL_INTERNAL].defaultPort = v;\n }\n }\n\n get protocol(): string {\n return (\n this[SYMBOL_INTERNAL].protocol ??\n (this.isSecureEndpoint() ? \"https:\" : \"http:\")\n );\n }\n\n set protocol(v: string) {\n if (this[SYMBOL_INTERNAL]) {\n this[SYMBOL_INTERNAL].protocol = v;\n }\n }\n}\n"],"mappings":"mNAsCA,MAAM,EAAkB,OAAO,QAAQ,CAQvC,IAAsB,EAAtB,cAAoC,EAAK,KAAM,CAC7C,CAAS,GAGT,QAEA,UAEA,YAAY,EAA0B,CACpC,MAAM,EAAK,CACX,KAAK,GAAmB,EAAE,CAW5B,iBAAiB,EAAqC,CACpD,GAAI,EAAS,CAGX,GAAI,EAAW,EAAgB,eAAe,CAC5C,OAAO,EAAQ,eAMjB,GAAI,EAAS,EAAQ,SAAS,CAC5B,OAAO,EAAQ,WAAa,SAOhC,GAAM,CAAE,SAAc,MAAM,IAAI,CAKhC,OAJK,EAAS,EAAM,CAIb,EACJ,MAAM;EAAK,CACX,KAAK,GAAK,EAAE,SAAS,aAAa,EAAI,EAAE,SAAS,cAAc,CAAC,CAL1D,GAcX,iBAAyB,EAAc,CAIrC,GAAI,KAAK,aAAe,KAAY,KAAK,kBAAoB,IAC3D,OAAO,KAOT,KAAK,QAAQ,KAAU,EAAE,CAEzB,IAAM,EAAa,IAAI,EAAI,OAAO,CAAE,SAAU,GAAO,CAAC,CAItD,OAHA,KAAK,QAAQ,GAAM,KAAK,EAAW,CAEnC,KAAK,mBACE,EAGT,iBAAyB,EAAc,EAA2B,CAChE,GAAI,CAAC,KAAK,QAAQ,IAAS,IAAW,KACpC,OAEF,IAAM,EAAU,KAAK,QAAQ,GACvB,EAAQ,EAAQ,QAAQ,EAAO,CACjC,IAAU,KACZ,EAAQ,OAAO,EAAO,EAAE,CAExB,KAAK,mBACD,EAAQ,SAAW,GAErB,OAAO,KAAK,QAAQ,IAO1B,QAAiB,EAAoC,CAOnD,OANuB,KAAK,iBAAiB,EAAQ,CAG5C,WAAW,UAAU,QAAQ,KAAK,KAAM,EAAQ,CAGlD,MAAM,QAAQ,EAAQ,CAG/B,aACE,EACA,EACA,EACA,CACA,IAAM,EAAc,CAClB,GAAG,EACH,eAAgB,KAAK,iBAAiB,EAAQ,CAC/C,CACK,EAAO,KAAK,QAAQ,EAAY,CAChC,EAAa,KAAK,iBAAiB,EAAK,CAC9C,QAAQ,SAAS,CACd,KAAK,SAAY,KAAK,QAAQ,EAAK,EAAY,CAAC,CAChD,KACC,GAAU,CAER,GADA,KAAK,iBAAiB,EAAM,EAAW,CACnC,aAAkB,EAAK,MACzB,GAAI,CAGF,OAAO,EAAO,WAAW,EAAK,EAAY,OACnCA,EAAc,CACrB,OAAO,EAAG,EAAa,CAG3B,KAAK,GAAiB,cAAgB,EAGtC,MAAM,aAAa,EAAK,EAAS,EAAG,EAEtC,GAAO,CACL,KAAK,iBAAiB,EAAM,EAAW,CACvC,EAAG,EAAI,EAEV,CAGL,kBAAoC,CAClC,IAAM,EAAS,KAAK,GAAiB,cAErC,GADA,KAAK,GAAiB,cAAgB,IAAA,GAClC,CAAC,EACH,MAAU,MAAM,qDAAqD,CAEvE,OAAO,EAGT,IAAI,aAAsB,CACxB,OACE,KAAK,GAAiB,cACrB,KAAK,WAAa,SAAW,IAAM,IAIxC,IAAI,YAAY,EAAW,CACrB,KAAK,KACP,KAAK,GAAiB,YAAc,GAIxC,IAAI,UAAmB,CACrB,OACE,KAAK,GAAiB,WACrB,KAAK,kBAAkB,CAAG,SAAW,SAI1C,IAAI,SAAS,EAAW,CAClB,KAAK,KACP,KAAK,GAAiB,SAAW"}
|
package/dist/fetch.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./type-checks/src/is-set-string.cjs`),n=require(`./url/src/helpers.cjs`),r=require(`./proxy-agent.cjs`);let i=require(`defu`),a=require(`undici`);async function o(e,o={}){if(t.isSetString(e)&&!n.isValidURL(e))throw Error(`Invalid URL format provided: ${e}`);let s=new AbortController;return setTimeout(()=>s.abort(),o.timeout??5e3),(0,a.fetch)(e,(0,i.defu)(o,{agent:r.getProxyAgent(),signal:s.signal,headers:{"User-Agent":`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36`}}))}const s=o;exports.fetch=s,exports.fetchRequest=o;
|
package/dist/fetch.d.cts
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as undici0 from "undici";
|
|
2
|
+
import { RequestInfo } from "undici";
|
|
3
|
+
|
|
4
|
+
//#region src/fetch.d.ts
|
|
5
|
+
type FetchRequestOptions = RequestInit & {
|
|
6
|
+
/**
|
|
7
|
+
* Timeout in milliseconds
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue 5000
|
|
10
|
+
*/
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Fetches a resource from a URL.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The URL to fetch.
|
|
17
|
+
* @param options - Additional fetch options.
|
|
18
|
+
* @returns The fetched response.
|
|
19
|
+
*/
|
|
20
|
+
declare function fetchRequest(input: RequestInfo, options?: FetchRequestOptions): Promise<undici0.Response>;
|
|
21
|
+
declare const fetch: typeof fetchRequest;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { FetchRequestOptions, fetch, fetchRequest };
|
|
24
|
+
//# sourceMappingURL=fetch.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.cts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;KAyBY,mBAAA,GAAsB;;;AAAlC;AAgBA;;EAEW,OAAA,CAAA,EAAA,MAAA;CAAwB;;;AAyBnC;;;;;iBA3BsB,YAAA,QACb,uBACE,sBAAwB,QAAA,OAAA,CAAA,QAAA;cAyBtB,cAAK"}
|
package/dist/fetch.d.mts
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as undici0 from "undici";
|
|
2
|
+
import { RequestInfo } from "undici";
|
|
3
|
+
|
|
4
|
+
//#region src/fetch.d.ts
|
|
5
|
+
type FetchRequestOptions = RequestInit & {
|
|
6
|
+
/**
|
|
7
|
+
* Timeout in milliseconds
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue 5000
|
|
10
|
+
*/
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Fetches a resource from a URL.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The URL to fetch.
|
|
17
|
+
* @param options - Additional fetch options.
|
|
18
|
+
* @returns The fetched response.
|
|
19
|
+
*/
|
|
20
|
+
declare function fetchRequest(input: RequestInfo, options?: FetchRequestOptions): Promise<undici0.Response>;
|
|
21
|
+
declare const fetch: typeof fetchRequest;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { FetchRequestOptions, fetch, fetchRequest };
|
|
24
|
+
//# sourceMappingURL=fetch.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.mts","names":[],"sources":["../src/fetch.ts"],"sourcesContent":[],"mappings":";;;;KAyBY,mBAAA,GAAsB;;;AAAlC;AAgBA;;EAEW,OAAA,CAAA,EAAA,MAAA;CAAwB;;;AAyBnC;;;;;iBA3BsB,YAAA,QACb,uBACE,sBAAwB,QAAA,OAAA,CAAA,QAAA;cAyBtB,cAAK"}
|
package/dist/fetch.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./
|
|
1
|
+
import{isSetString as e}from"./type-checks/src/is-set-string.mjs";import{isValidURL as t}from"./url/src/helpers.mjs";import{getProxyAgent as n}from"./proxy-agent.mjs";import{defu as r}from"defu";import{fetch as i}from"undici";async function a(a,o={}){if(e(a)&&!t(a))throw Error(`Invalid URL format provided: ${a}`);let s=new AbortController;return setTimeout(()=>s.abort(),o.timeout??5e3),i(a,r(o,{agent:n(),signal:s.signal,headers:{"User-Agent":`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36`}}))}const o=a;export{o as fetch,a as fetchRequest};
|
|
2
|
+
//# sourceMappingURL=fetch.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.mjs","names":["undiciFetch"],"sources":["../src/fetch.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isValidURL } from \"@stryke/url/helpers\";\nimport { defu } from \"defu\";\nimport type { RequestInfo } from \"undici\";\nimport { fetch as undiciFetch } from \"undici\";\nimport { getProxyAgent } from \"./proxy-agent\";\n\nexport type FetchRequestOptions = RequestInit & {\n /**\n * Timeout in milliseconds\n *\n * @defaultValue 5000\n */\n timeout?: number;\n};\n\n/**\n * Fetches a resource from a URL.\n *\n * @param input - The URL to fetch.\n * @param options - Additional fetch options.\n * @returns The fetched response.\n */\nexport async function fetchRequest(\n input: RequestInfo,\n options: FetchRequestOptions = {}\n) {\n if (isSetString(input) && !isValidURL(input)) {\n throw new Error(`Invalid URL format provided: ${input}`);\n }\n\n const abort = new AbortController();\n setTimeout(() => abort.abort(), options.timeout ?? 5000);\n\n return undiciFetch(\n input,\n defu(options, {\n agent: getProxyAgent(),\n signal: abort.signal,\n headers: {\n // The file format is based off of the user agent, make sure woff2 files are fetched\n \"User-Agent\":\n \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \" +\n \"AppleWebKit/537.36 (KHTML, like Gecko) \" +\n \"Chrome/104.0.0.0 Safari/537.36\"\n }\n })\n );\n}\n\nexport const fetch = fetchRequest;\n"],"mappings":"kOAyCA,eAAsB,EACpB,EACA,EAA+B,EAAE,CACjC,CACA,GAAI,EAAY,EAAM,EAAI,CAAC,EAAW,EAAM,CAC1C,MAAU,MAAM,gCAAgC,IAAQ,CAG1D,IAAM,EAAQ,IAAI,gBAGlB,OAFA,eAAiB,EAAM,OAAO,CAAE,EAAQ,SAAW,IAAK,CAEjDA,EACL,EACA,EAAK,EAAS,CACZ,MAAO,GAAe,CACtB,OAAQ,EAAM,OACd,QAAS,CAEP,aACE,wHAGH,CACF,CAAC,CACH,CAGH,MAAa,EAAQ"}
|
package/dist/format-data-uri.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=
|
|
1
|
+
const e=(e,t)=>`data:${t};utf8,${encodeURIComponent(e)}`,t=e=>t=>{if(t=String(t),!/^data:/i.test(t))throw Error('`uri` does not appear to be a Data URI (must begin with "data:")');t=t.replace(/\r?\n/g,``);let n=t.indexOf(`,`);if(n===-1||n<=4)throw Error(`malformed data: URI`);let r=t.substring(5,n).split(`;`),i=``,a=!1,o=r[0]||`text/plain`,s=o;for(let e=1;e<r.length;e++)r[e]===`base64`?a=!0:r[e]&&(s+=`;${r[e]}`,r[e]?.indexOf(`charset=`)===0&&(i=r[e].substring(8)));!r[0]&&!i.length&&(s+=`;charset=US-ASCII`,i=`US-ASCII`);let c=unescape(t.substring(n+1)),l=a?e.base64ToArrayBuffer(c):e.stringToBuffer(c);return{type:o,typeFull:s,charset:i,buffer:l}};exports.formatDataURI=e,exports.makeDataUriToBuffer=t;
|
|
@@ -1,2 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/format-data-uri.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a data URI from a string of data.
|
|
4
|
+
*
|
|
5
|
+
* @param data - The data to convert to a data URI.
|
|
6
|
+
* @param mime - The MIME type of the data.
|
|
7
|
+
* @returns The data URI.
|
|
8
|
+
*/
|
|
9
|
+
declare const formatDataURI: (data: string, mime: string) => string;
|
|
10
|
+
interface ParsedDataURI {
|
|
11
|
+
type: string;
|
|
12
|
+
typeFull: string;
|
|
13
|
+
charset: string;
|
|
14
|
+
buffer: ArrayBuffer;
|
|
15
|
+
}
|
|
16
|
+
interface BufferConversionsInterface {
|
|
17
|
+
base64ToArrayBuffer: (base64: string) => ArrayBuffer;
|
|
18
|
+
stringToBuffer: (str: string) => ArrayBuffer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns a `Buffer` instance from the given data URI `uri`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { makeDataUriToBuffer } from "@stryke/core/http";
|
|
26
|
+
*
|
|
27
|
+
* const dataUriToBuffer = makeDataUriToBuffer({
|
|
28
|
+
* base64ToArrayBuffer: (base64) => Buffer.from(base64, "base64").buffer,
|
|
29
|
+
* stringToBuffer: (str) => Buffer.from(str, "utf8")https://avatars.githubusercontent.com/u/99053093?s=64&v=4.buffer,
|
|
30
|
+
* });
|
|
31
|
+
* const parsed = dataUriToBuffer("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==");
|
|
32
|
+
* console.log(parsed);
|
|
33
|
+
* // {
|
|
34
|
+
* // type: 'text/plain',
|
|
35
|
+
* // typeFull: 'text/plain;base64',
|
|
36
|
+
* // charset: '',
|
|
37
|
+
* // buffer: ArrayBuffer { ... }
|
|
38
|
+
* // }
|
|
39
|
+
* console.log(Buffer.from(parsed.buffer).toString("utf8"));
|
|
40
|
+
* // Hello, World!
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param convert - Conversion functions
|
|
44
|
+
* @returns An object containing the parsed data URI properties and the decoded data as a Buffer instance.
|
|
45
|
+
* @throws `TypeError` if `uri` is not a valid Data URI
|
|
46
|
+
*/
|
|
47
|
+
declare const makeDataUriToBuffer: (convert: BufferConversionsInterface) => (uri: string | URL) => ParsedDataURI;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { BufferConversionsInterface, ParsedDataURI, formatDataURI, makeDataUriToBuffer };
|
|
50
|
+
//# sourceMappingURL=format-data-uri.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-data-uri.d.cts","names":[],"sources":["../src/format-data-uri.ts"],"sourcesContent":[],"mappings":";;AAyBA;AAGA;AAOA;AAgCA;;;AAEuB,cA5CV,aA4CU,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAsDpB,UA/Fc,aAAA,CA+Fd;;;;UA3FO;;UAGO,0BAAA;2CAC0B;mCACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BtB,+BACD,8CACK,QAAM"}
|
|
@@ -1,2 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/format-data-uri.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a data URI from a string of data.
|
|
4
|
+
*
|
|
5
|
+
* @param data - The data to convert to a data URI.
|
|
6
|
+
* @param mime - The MIME type of the data.
|
|
7
|
+
* @returns The data URI.
|
|
8
|
+
*/
|
|
9
|
+
declare const formatDataURI: (data: string, mime: string) => string;
|
|
10
|
+
interface ParsedDataURI {
|
|
11
|
+
type: string;
|
|
12
|
+
typeFull: string;
|
|
13
|
+
charset: string;
|
|
14
|
+
buffer: ArrayBuffer;
|
|
15
|
+
}
|
|
16
|
+
interface BufferConversionsInterface {
|
|
17
|
+
base64ToArrayBuffer: (base64: string) => ArrayBuffer;
|
|
18
|
+
stringToBuffer: (str: string) => ArrayBuffer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns a `Buffer` instance from the given data URI `uri`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { makeDataUriToBuffer } from "@stryke/core/http";
|
|
26
|
+
*
|
|
27
|
+
* const dataUriToBuffer = makeDataUriToBuffer({
|
|
28
|
+
* base64ToArrayBuffer: (base64) => Buffer.from(base64, "base64").buffer,
|
|
29
|
+
* stringToBuffer: (str) => Buffer.from(str, "utf8")https://avatars.githubusercontent.com/u/99053093?s=64&v=4.buffer,
|
|
30
|
+
* });
|
|
31
|
+
* const parsed = dataUriToBuffer("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==");
|
|
32
|
+
* console.log(parsed);
|
|
33
|
+
* // {
|
|
34
|
+
* // type: 'text/plain',
|
|
35
|
+
* // typeFull: 'text/plain;base64',
|
|
36
|
+
* // charset: '',
|
|
37
|
+
* // buffer: ArrayBuffer { ... }
|
|
38
|
+
* // }
|
|
39
|
+
* console.log(Buffer.from(parsed.buffer).toString("utf8"));
|
|
40
|
+
* // Hello, World!
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param convert - Conversion functions
|
|
44
|
+
* @returns An object containing the parsed data URI properties and the decoded data as a Buffer instance.
|
|
45
|
+
* @throws `TypeError` if `uri` is not a valid Data URI
|
|
46
|
+
*/
|
|
47
|
+
declare const makeDataUriToBuffer: (convert: BufferConversionsInterface) => (uri: string | URL) => ParsedDataURI;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { BufferConversionsInterface, ParsedDataURI, formatDataURI, makeDataUriToBuffer };
|
|
50
|
+
//# sourceMappingURL=format-data-uri.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-data-uri.d.mts","names":[],"sources":["../src/format-data-uri.ts"],"sourcesContent":[],"mappings":";;AAyBA;AAGA;AAOA;AAgCA;;;AAEuB,cA5CV,aA4CU,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AAsDpB,UA/Fc,aAAA,CA+Fd;;;;UA3FO;;UAGO,0BAAA;2CAC0B;mCACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BtB,+BACD,8CACK,QAAM"}
|
package/dist/format-data-uri.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=(e,t)=>`data:${t};utf8,${encodeURIComponent(e)}`,t=e=>t=>{if(t=String(t),!/^data:/i.test(t))throw Error('`uri` does not appear to be a Data URI (must begin with "data:")');t=t.replace(/\r?\n/g,``);let n=t.indexOf(`,`);if(n===-1||n<=4)throw Error(`malformed data: URI`);let r=t.substring(5,n).split(`;`),i=``,a=!1,o=r[0]||`text/plain`,s=o;for(let e=1;e<r.length;e++)r[e]===`base64`?a=!0:r[e]&&(s+=`;${r[e]}`,r[e]?.indexOf(`charset=`)===0&&(i=r[e].substring(8)));!r[0]&&!i.length&&(s+=`;charset=US-ASCII`,i=`US-ASCII`);let c=unescape(t.substring(n+1)),l=a?e.base64ToArrayBuffer(c):e.stringToBuffer(c);return{type:o,typeFull:s,charset:i,buffer:l}};export{e as formatDataURI,t as makeDataUriToBuffer};
|
|
2
|
+
//# sourceMappingURL=format-data-uri.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-data-uri.mjs","names":[],"sources":["../src/format-data-uri.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Creates a data URI from a string of data.\n *\n * @param data - The data to convert to a data URI.\n * @param mime - The MIME type of the data.\n * @returns The data URI.\n */\nexport const formatDataURI = (data: string, mime: string): string =>\n `data:${mime};utf8,${encodeURIComponent(data)}`;\n\nexport interface ParsedDataURI {\n type: string;\n typeFull: string;\n charset: string;\n buffer: ArrayBuffer;\n}\n\nexport interface BufferConversionsInterface {\n base64ToArrayBuffer: (base64: string) => ArrayBuffer;\n stringToBuffer: (str: string) => ArrayBuffer;\n}\n\n/**\n * Returns a `Buffer` instance from the given data URI `uri`.\n *\n * @example\n * ```typescript\n * import { makeDataUriToBuffer } from \"@stryke/core/http\";\n *\n * const dataUriToBuffer = makeDataUriToBuffer({\n * base64ToArrayBuffer: (base64) => Buffer.from(base64, \"base64\").buffer,\n * stringToBuffer: (str) => Buffer.from(str, \"utf8\")https://avatars.githubusercontent.com/u/99053093?s=64&v=4.buffer,\n * });\n * const parsed = dataUriToBuffer(\"data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==\");\n * console.log(parsed);\n * // {\n * // type: 'text/plain',\n * // typeFull: 'text/plain;base64',\n * // charset: '',\n * // buffer: ArrayBuffer { ... }\n * // }\n * console.log(Buffer.from(parsed.buffer).toString(\"utf8\"));\n * // Hello, World!\n * ```\n *\n * @param convert - Conversion functions\n * @returns An object containing the parsed data URI properties and the decoded data as a Buffer instance.\n * @throws `TypeError` if `uri` is not a valid Data URI\n */\nexport const makeDataUriToBuffer =\n (convert: BufferConversionsInterface) =>\n (uri: string | URL): ParsedDataURI => {\n uri = String(uri);\n\n if (!/^data:/i.test(uri)) {\n throw new Error(\n '`uri` does not appear to be a Data URI (must begin with \"data:\")'\n );\n }\n\n // strip newlines\n uri = uri.replace(/\\r?\\n/g, \"\");\n\n // split the URI up into the \"metadata\" and the \"data\" portions\n const firstComma = uri.indexOf(\",\");\n if (firstComma === -1 || firstComma <= 4) {\n throw new Error(\"malformed data: URI\");\n }\n\n // remove the \"data:\" scheme and parse the metadata\n const meta = uri.substring(5, firstComma).split(\";\");\n\n let charset = \"\";\n let base64 = false;\n const type = meta[0] || \"text/plain\";\n let typeFull = type;\n for (let i = 1; i < meta.length; i++) {\n if (meta[i] === \"base64\") {\n base64 = true;\n } else if (meta[i]) {\n typeFull += `;${meta[i]}`;\n if (meta[i]?.indexOf(\"charset=\") === 0) {\n charset = meta[i]!.substring(8);\n }\n }\n }\n\n // defaults to US-ASCII only if type is not provided\n if (!meta[0] && !charset.length) {\n typeFull += \";charset=US-ASCII\";\n charset = \"US-ASCII\";\n }\n\n // get the encoded data portion and decode URI-encoded chars\n const data = unescape(uri.substring(firstComma + 1));\n const buffer = base64\n ? convert.base64ToArrayBuffer(data)\n : convert.stringToBuffer(data);\n\n return {\n type,\n typeFull,\n charset,\n buffer\n };\n };\n"],"mappings":"AAyBA,MAAa,GAAiB,EAAc,IAC1C,QAAQ,EAAK,QAAQ,mBAAmB,EAAK,GAyClC,EACV,GACA,GAAqC,CAGpC,GAFA,EAAM,OAAO,EAAI,CAEb,CAAC,UAAU,KAAK,EAAI,CACtB,MAAU,MACR,mEACD,CAIH,EAAM,EAAI,QAAQ,SAAU,GAAG,CAG/B,IAAM,EAAa,EAAI,QAAQ,IAAI,CACnC,GAAI,IAAe,IAAM,GAAc,EACrC,MAAU,MAAM,sBAAsB,CAIxC,IAAM,EAAO,EAAI,UAAU,EAAG,EAAW,CAAC,MAAM,IAAI,CAEhD,EAAU,GACV,EAAS,GACP,EAAO,EAAK,IAAM,aACpB,EAAW,EACf,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAC3B,EAAK,KAAO,SACd,EAAS,GACA,EAAK,KACd,GAAY,IAAI,EAAK,KACjB,EAAK,IAAI,QAAQ,WAAW,GAAK,IACnC,EAAU,EAAK,GAAI,UAAU,EAAE,GAMjC,CAAC,EAAK,IAAM,CAAC,EAAQ,SACvB,GAAY,oBACZ,EAAU,YAIZ,IAAM,EAAO,SAAS,EAAI,UAAU,EAAa,EAAE,CAAC,CAC9C,EAAS,EACX,EAAQ,oBAAoB,EAAK,CACjC,EAAQ,eAAe,EAAK,CAEhC,MAAO,CACL,OACA,WACA,UACA,SACD"}
|
package/dist/get-free-port.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`);let t=require(`node:http`);async function n(){return new Promise((e,n)=>{let r=(0,t.createServer)(()=>{});r.listen(0,()=>{let t=r.address();r.close(),t&&typeof t==`object`?e(t.port):n(Error(`invalid address from server: ${t?.toString()}`))})})}exports.getFreePort=n;
|
package/dist/get-free-port.d.cts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/get-free-port.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Finds and returns a free port on the local machine by creating a temporary server that listens on port 0. The operating system assigns an available port, which is then retrieved and returned.
|
|
4
|
+
*
|
|
5
|
+
* @returns A promise that resolves to a free port number.
|
|
6
|
+
*/
|
|
7
|
+
declare function getFreePort(): Promise<number>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getFreePort };
|
|
10
|
+
//# sourceMappingURL=get-free-port.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-free-port.d.cts","names":[],"sources":["../src/get-free-port.ts"],"sourcesContent":[],"mappings":";;AAyBA;;;;iBAAsB,WAAA,CAAA,GAAe"}
|
package/dist/get-free-port.d.mts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/get-free-port.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Finds and returns a free port on the local machine by creating a temporary server that listens on port 0. The operating system assigns an available port, which is then retrieved and returned.
|
|
4
|
+
*
|
|
5
|
+
* @returns A promise that resolves to a free port number.
|
|
6
|
+
*/
|
|
7
|
+
declare function getFreePort(): Promise<number>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getFreePort };
|
|
10
|
+
//# sourceMappingURL=get-free-port.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-free-port.d.mts","names":[],"sources":["../src/get-free-port.ts"],"sourcesContent":[],"mappings":";;AAyBA;;;;iBAAsB,WAAA,CAAA,GAAe"}
|
package/dist/get-free-port.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createServer as e}from"node:http";async function t(){return new Promise((t,n)=>{let r=e(()=>{});r.listen(0,()=>{let e=r.address();r.close(),e&&typeof e==`object`?t(e.port):n(Error(`invalid address from server: ${e?.toString()}`))})})}export{t as getFreePort};
|
|
2
|
+
//# sourceMappingURL=get-free-port.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-free-port.mjs","names":[],"sources":["../src/get-free-port.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createServer } from \"node:http\";\n\n/**\n * Finds and returns a free port on the local machine by creating a temporary server that listens on port 0. The operating system assigns an available port, which is then retrieved and returned.\n *\n * @returns A promise that resolves to a free port number.\n */\nexport async function getFreePort(): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = createServer(() => {});\n server.listen(0, () => {\n const address = server.address();\n server.close();\n\n if (address && typeof address === \"object\") {\n resolve(address.port);\n } else {\n reject(\n new Error(`invalid address from server: ${address?.toString()}`)\n );\n }\n });\n });\n}\n"],"mappings":"yCAyBA,eAAsB,GAA+B,CACnD,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,IAAM,EAAS,MAAmB,GAAG,CACrC,EAAO,OAAO,MAAS,CACrB,IAAM,EAAU,EAAO,SAAS,CAChC,EAAO,OAAO,CAEV,GAAW,OAAO,GAAY,SAChC,EAAQ,EAAQ,KAAK,CAErB,EACM,MAAM,gCAAgC,GAAS,UAAU,GAAG,CACjE,EAEH,EACF"}
|
package/dist/http-proxy.cjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
require(`./agent
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./agent.cjs`);let n=require(`node:net`);n=e.__toESM(n);let r=require(`node:buffer`),i=require(`node:events`),a=require(`node:tls`);a=e.__toESM(a);let o=require(`node:url`);var s=class extends t.Agent{static protocols=[`http`,`https`];proxy;proxyHeaders;connectOpts;constructor(e,t){super(t),this.proxy=typeof e==`string`?new o.URL(e):e,this.proxyHeaders=t?.headers??{};let n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),r=this.proxy.port?Number.parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={...t?c(t,`headers`):null,host:n,port:r}}addRequest(e,t){e._header=null,this.setRequestProps(e,t),super.addRequest(e,t)}setRequestProps(e,t){let{proxy:n}=this,i=t.secureEndpoint?`https:`:`http:`,a=e.getHeader(`host`)||`localhost`,s=`${i}//${Array.isArray(a)?a.join(``):a}`,c=new o.URL(e.path,s);t.port!==80&&(c.port=String(t.port)),e.path=String(c);let l=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders};if(n.username||n.password){let e=`${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`;l[`Proxy-Authorization`]=`Basic ${r.Buffer.from(e).toString(`base64`)}`}l[`Proxy-Connection`]||=this.keepAlive?`Keep-Alive`:`close`;for(let t of Object.keys(l)){let n=l[t];n&&e.setHeader(t,n)}}async connect(e,t){e._header=null,e.path.includes(`://`)||this.setRequestProps(e,t);let r,o;e._implicitHeader(),e.outputData&&e.outputData.length>0&&(r=e.outputData[0].data,o=r.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`)+4,e.outputData[0].data=e._header+r.substring(o));let s;return s=this.proxy.protocol===`https:`?a.connect(this.connectOpts):n.connect(this.connectOpts),await(0,i.once)(s,`connect`),s}};function c(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}exports.HttpProxyAgent=s;
|
package/dist/http-proxy.d.cts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Agent as Agent$1 } from "./agent.cjs";
|
|
2
|
+
import { AgentOptions, ClientRequest, OutgoingHttpHeaders } from "node:http";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import * as tls from "node:tls";
|
|
5
|
+
import { AgentConnectOpts } from "agent-base";
|
|
6
|
+
import { URL } from "node:url";
|
|
7
|
+
|
|
8
|
+
//#region src/http-proxy.d.ts
|
|
9
|
+
type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
|
|
10
|
+
interface ConnectOptsMap {
|
|
11
|
+
http: Omit<net.TcpNetConnectOpts, "host" | "port">;
|
|
12
|
+
https: Omit<tls.ConnectionOptions, "host" | "port">;
|
|
13
|
+
}
|
|
14
|
+
type ConnectOpts<T> = { [P in keyof ConnectOptsMap]: Protocol<T> extends P ? ConnectOptsMap[P] : never }[keyof ConnectOptsMap];
|
|
15
|
+
type HttpProxyAgentOptions<T> = ConnectOpts<T> & AgentOptions & {
|
|
16
|
+
headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
|
|
17
|
+
};
|
|
18
|
+
interface HttpProxyAgentClientRequest extends ClientRequest {
|
|
19
|
+
outputData?: {
|
|
20
|
+
data: string;
|
|
21
|
+
}[];
|
|
22
|
+
_header?: string | null;
|
|
23
|
+
_implicitHeader: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects to the specified "HTTP proxy server" in order to proxy HTTP requests.
|
|
27
|
+
*/
|
|
28
|
+
declare class HttpProxyAgent<Uri extends string> extends Agent$1 {
|
|
29
|
+
static protocols: readonly ["http", "https"];
|
|
30
|
+
readonly proxy: URL;
|
|
31
|
+
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
|
|
32
|
+
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
|
|
33
|
+
constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>);
|
|
34
|
+
addRequest(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
|
|
35
|
+
setRequestProps(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
|
|
36
|
+
connect(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { HttpProxyAgent, HttpProxyAgentOptions };
|
|
40
|
+
//# sourceMappingURL=http-proxy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-proxy.d.cts","names":[],"sources":["../src/http-proxy.ts"],"sourcesContent":[],"mappings":";;;;;;;;KA+BK,cAAc;UAET,cAAA;EAFL,IAAA,EAGG,IAHH,CAGQ,GAAA,CAAI,iBAHG,EAAA,MAAA,GAAA,MAAA,CAAA;EAEV,KAAA,EAED,IAFC,CAEI,GAAA,CAAI,iBAFM,EAAA,MAAA,GAAA,MAAA,CAAA;;KAKnB,WAJG,CAAA,CAAA,CAAA,GAAA,QACU,MAIJ,cAJI,GAIa,QAJb,CAIsB,CAJtB,CAAA,SAIiC,CAJjC,GAKZ,cALY,CAKG,CALH,CAAA,GAAA,KAAA,EAAT,CAAA,MAOD,cAPC,CAAA;AAAI,KASD,qBATC,CAAA,CAAA,CAAA,GAS0B,WAT1B,CASsC,CATtC,CAAA,GAUX,YAVW,GAAA;EAGR,OAAA,CAAA,EAQS,mBARE,GAAA,CAAA,GAAA,GAQ2B,mBAR3B,CAAA;CACF;UAUJ,2BAAA,SAAoC,aAVN,CAAA;EAAT,UAAA,CAAA,EAAA;IAAoB,IAAA,EAAA,MAAA;EAC7C,CAAA,EAAA;EAAe,OAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAEb,eAAA,EAAA,GAAA,GAAA,IAAA;;AAER;;;AACE,cAeW,cAfX,CAAA,YAAA,MAAA,CAAA,SAesD,OAAA,CAftD;EACY,OAAA,SAAA,EAAA,SAAA,CAAA,MAAA,EAAA,OAAA,CAAA;EAA6B,SAAA,KAAA,EAiBzB,GAjByB;EAAmB,YAAA,EAmB9C,mBAnB8C,GAAA,CAAA,GAAA,GAmBjB,mBAnBiB,CAAA;EAGpD,WAAA,EAkBK,GAAA,CAAI,iBAlBmB,GAkBC,GAAA,CAAI,iBAlBgB;EAW9C,WAAA,CAAA,KAAc,EASN,GATM,GASA,GATA,EAAA,IAAA,CAAA,EASY,qBATZ,CASkC,GATlC,CAAA;EAGT,UAAA,CAAA,GAAA,EA4BA,2BA5BA,EAAA,IAAA,EA4BmC,gBA5BnC,CAAA,EAAA,IAAA;EAEF,eAAA,CAAA,GAAA,EAoCP,2BApCO,EAAA,IAAA,EAqCN,gBArCM,CAAA,EAAA,IAAA;EAA6B,OAAA,CAAA,GAAA,EA+EpC,2BA/EoC,EAAA,IAAA,EAgFnC,gBAhFmC,CAAA,EAiFxC,OAjFwC,CAiFhC,GAAA,CAAI,MAjF4B,CAAA"}
|
package/dist/http-proxy.d.mts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Agent as Agent$1 } from "./agent.mjs";
|
|
2
|
+
import { AgentOptions, ClientRequest, OutgoingHttpHeaders } from "node:http";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import * as tls from "node:tls";
|
|
5
|
+
import { URL } from "node:url";
|
|
6
|
+
import { AgentConnectOpts } from "agent-base";
|
|
7
|
+
|
|
8
|
+
//#region src/http-proxy.d.ts
|
|
9
|
+
type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
|
|
10
|
+
interface ConnectOptsMap {
|
|
11
|
+
http: Omit<net.TcpNetConnectOpts, "host" | "port">;
|
|
12
|
+
https: Omit<tls.ConnectionOptions, "host" | "port">;
|
|
13
|
+
}
|
|
14
|
+
type ConnectOpts<T> = { [P in keyof ConnectOptsMap]: Protocol<T> extends P ? ConnectOptsMap[P] : never }[keyof ConnectOptsMap];
|
|
15
|
+
type HttpProxyAgentOptions<T> = ConnectOpts<T> & AgentOptions & {
|
|
16
|
+
headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
|
|
17
|
+
};
|
|
18
|
+
interface HttpProxyAgentClientRequest extends ClientRequest {
|
|
19
|
+
outputData?: {
|
|
20
|
+
data: string;
|
|
21
|
+
}[];
|
|
22
|
+
_header?: string | null;
|
|
23
|
+
_implicitHeader: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects to the specified "HTTP proxy server" in order to proxy HTTP requests.
|
|
27
|
+
*/
|
|
28
|
+
declare class HttpProxyAgent<Uri extends string> extends Agent$1 {
|
|
29
|
+
static protocols: readonly ["http", "https"];
|
|
30
|
+
readonly proxy: URL;
|
|
31
|
+
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
|
|
32
|
+
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
|
|
33
|
+
constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>);
|
|
34
|
+
addRequest(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
|
|
35
|
+
setRequestProps(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void;
|
|
36
|
+
connect(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { HttpProxyAgent, HttpProxyAgentOptions };
|
|
40
|
+
//# sourceMappingURL=http-proxy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-proxy.d.mts","names":[],"sources":["../src/http-proxy.ts"],"sourcesContent":[],"mappings":";;;;;;;;KA+BK,cAAc;UAET,cAAA;EAFL,IAAA,EAGG,IAHH,CAGQ,GAAA,CAAI,iBAHG,EAAA,MAAA,GAAA,MAAA,CAAA;EAEV,KAAA,EAED,IAFC,CAEI,GAAA,CAAI,iBAFM,EAAA,MAAA,GAAA,MAAA,CAAA;;KAKnB,WAJG,CAAA,CAAA,CAAA,GAAA,QACU,MAIJ,cAJI,GAIa,QAJb,CAIsB,CAJtB,CAAA,SAIiC,CAJjC,GAKZ,cALY,CAKG,CALH,CAAA,GAAA,KAAA,EAAT,CAAA,MAOD,cAPC,CAAA;AAAI,KASD,qBATC,CAAA,CAAA,CAAA,GAS0B,WAT1B,CASsC,CATtC,CAAA,GAUX,YAVW,GAAA;EAGR,OAAA,CAAA,EAQS,mBARE,GAAA,CAAA,GAAA,GAQ2B,mBAR3B,CAAA;CACF;UAUJ,2BAAA,SAAoC,aAVN,CAAA;EAAT,UAAA,CAAA,EAAA;IAAoB,IAAA,EAAA,MAAA;EAC7C,CAAA,EAAA;EAAe,OAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAEb,eAAA,EAAA,GAAA,GAAA,IAAA;;AAER;;;AACE,cAeW,cAfX,CAAA,YAAA,MAAA,CAAA,SAesD,OAAA,CAftD;EACY,OAAA,SAAA,EAAA,SAAA,CAAA,MAAA,EAAA,OAAA,CAAA;EAA6B,SAAA,KAAA,EAiBzB,GAjByB;EAAmB,YAAA,EAmB9C,mBAnB8C,GAAA,CAAA,GAAA,GAmBjB,mBAnBiB,CAAA;EAGpD,WAAA,EAkBK,GAAA,CAAI,iBAlBmB,GAkBC,GAAA,CAAI,iBAlBgB;EAW9C,WAAA,CAAA,KAAc,EASN,GATM,GASA,GATA,EAAA,IAAA,CAAA,EASY,qBATZ,CASkC,GATlC,CAAA;EAGT,UAAA,CAAA,GAAA,EA4BA,2BA5BA,EAAA,IAAA,EA4BmC,gBA5BnC,CAAA,EAAA,IAAA;EAEF,eAAA,CAAA,GAAA,EAoCP,2BApCO,EAAA,IAAA,EAqCN,gBArCM,CAAA,EAAA,IAAA;EAA6B,OAAA,CAAA,GAAA,EA+EpC,2BA/EoC,EAAA,IAAA,EAgFnC,gBAhFmC,CAAA,EAiFxC,OAjFwC,CAiFhC,GAAA,CAAI,MAjF4B,CAAA"}
|
package/dist/http-proxy.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import"./agent
|
|
1
|
+
import{Agent as e}from"./agent.mjs";import*as t from"node:net";import{Buffer as n}from"node:buffer";import{once as r}from"node:events";import*as i from"node:tls";import{URL as a}from"node:url";var o=class extends e{static protocols=[`http`,`https`];proxy;proxyHeaders;connectOpts;constructor(e,t){super(t),this.proxy=typeof e==`string`?new a(e):e,this.proxyHeaders=t?.headers??{};let n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),r=this.proxy.port?Number.parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={...t?s(t,`headers`):null,host:n,port:r}}addRequest(e,t){e._header=null,this.setRequestProps(e,t),super.addRequest(e,t)}setRequestProps(e,t){let{proxy:r}=this,i=t.secureEndpoint?`https:`:`http:`,o=e.getHeader(`host`)||`localhost`,s=`${i}//${Array.isArray(o)?o.join(``):o}`,c=new a(e.path,s);t.port!==80&&(c.port=String(t.port)),e.path=String(c);let l=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders};if(r.username||r.password){let e=`${decodeURIComponent(r.username)}:${decodeURIComponent(r.password)}`;l[`Proxy-Authorization`]=`Basic ${n.from(e).toString(`base64`)}`}l[`Proxy-Connection`]||=this.keepAlive?`Keep-Alive`:`close`;for(let t of Object.keys(l)){let n=l[t];n&&e.setHeader(t,n)}}async connect(e,n){e._header=null,e.path.includes(`://`)||this.setRequestProps(e,n);let a,o;e._implicitHeader(),e.outputData&&e.outputData.length>0&&(a=e.outputData[0].data,o=a.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`)+4,e.outputData[0].data=e._header+a.substring(o));let s;return s=this.proxy.protocol===`https:`?i.connect(this.connectOpts):t.connect(this.connectOpts),await r(s,`connect`),s}};function s(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}export{o as HttpProxyAgent};
|
|
4
|
+
//# sourceMappingURL=http-proxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-proxy.mjs","names":["headers: OutgoingHttpHeaders","first: string","endOfHeaders: number","socket: net.Socket","key: keyof typeof obj"],"sources":["../src/http-proxy.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { AgentConnectOpts } from \"agent-base\";\nimport { Buffer } from \"node:buffer\";\nimport { once } from \"node:events\";\nimport type {\n AgentOptions,\n ClientRequest,\n OutgoingHttpHeaders\n} from \"node:http\";\nimport * as net from \"node:net\";\nimport * as tls from \"node:tls\";\nimport { URL } from \"node:url\";\nimport { Agent } from \"./agent\";\n\ntype Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;\n\ninterface ConnectOptsMap {\n http: Omit<net.TcpNetConnectOpts, \"host\" | \"port\">;\n https: Omit<tls.ConnectionOptions, \"host\" | \"port\">;\n}\n\ntype ConnectOpts<T> = {\n [P in keyof ConnectOptsMap]: Protocol<T> extends P\n ? ConnectOptsMap[P]\n : never;\n}[keyof ConnectOptsMap];\n\nexport type HttpProxyAgentOptions<T> = ConnectOpts<T> &\n AgentOptions & {\n headers?: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);\n };\n\ninterface HttpProxyAgentClientRequest extends ClientRequest {\n outputData?: {\n data: string;\n }[];\n _header?: string | null;\n _implicitHeader: () => void;\n}\n\n/**\n * The `HttpProxyAgent` implements an HTTP Agent subclass that connects to the specified \"HTTP proxy server\" in order to proxy HTTP requests.\n */\nexport class HttpProxyAgent<Uri extends string> extends Agent {\n static protocols = [\"http\", \"https\"] as const;\n\n readonly proxy: URL;\n\n proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);\n\n connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;\n\n constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>) {\n super(opts);\n this.proxy = typeof proxy === \"string\" ? new URL(proxy) : proxy;\n this.proxyHeaders = opts?.headers ?? {};\n\n // Trim off the brackets from IPv6 addresses\n const host = (this.proxy.hostname || this.proxy.host).replace(\n /^\\[|\\]$/g,\n \"\"\n );\n const port = this.proxy.port\n ? Number.parseInt(this.proxy.port, 10)\n : this.proxy.protocol === \"https:\"\n ? 443\n : 80;\n this.connectOpts = {\n ...(opts ? omit(opts, \"headers\") : null),\n host,\n port\n };\n }\n\n addRequest(req: HttpProxyAgentClientRequest, opts: AgentConnectOpts): void {\n req._header = null;\n this.setRequestProps(req, opts);\n\n // @ts-expect-error `addRequest()` isn't defined in `@types/node`\n // eslint-disable-next-line ts/no-unsafe-call\n super.addRequest(req, opts);\n }\n\n setRequestProps(\n req: HttpProxyAgentClientRequest,\n opts: AgentConnectOpts\n ): void {\n const { proxy } = this;\n const protocol = opts.secureEndpoint ? \"https:\" : \"http:\";\n const hostname = req.getHeader(\"host\") || \"localhost\";\n const base = `${protocol}//${Array.isArray(hostname) ? hostname.join(\"\") : hostname}`;\n const url = new URL(req.path, base);\n if (opts.port !== 80) {\n url.port = String(opts.port);\n }\n\n // Change the `http.ClientRequest` instance's \"path\" field\n // to the absolute path of the URL that will be requested.\n req.path = String(url);\n\n // Inject the `Proxy-Authorization` header if necessary.\n\n const headers: OutgoingHttpHeaders =\n typeof this.proxyHeaders === \"function\"\n ? this.proxyHeaders()\n : { ...this.proxyHeaders };\n if (proxy.username || proxy.password) {\n const auth = `${decodeURIComponent(\n proxy.username\n )}:${decodeURIComponent(proxy.password)}`;\n headers[\"Proxy-Authorization\"] = `Basic ${Buffer.from(auth).toString(\n \"base64\"\n )}`;\n }\n\n if (!headers[\"Proxy-Connection\"]) {\n headers[\"Proxy-Connection\"] = this.keepAlive ? \"Keep-Alive\" : \"close\";\n }\n for (const name of Object.keys(headers)) {\n const value = headers[name];\n if (value) {\n req.setHeader(name, value);\n }\n }\n }\n\n async connect(\n req: HttpProxyAgentClientRequest,\n opts: AgentConnectOpts\n ): Promise<net.Socket> {\n req._header = null;\n\n if (!req.path.includes(\"://\")) {\n this.setRequestProps(req, opts);\n }\n\n // At this point, the http ClientRequest's internal `_header` field\n // might have already been set. If this is the case then we'll need\n // to re-generate the string since we just changed the `req.path`.\n let first: string;\n let endOfHeaders: number;\n\n req._implicitHeader();\n if (req.outputData && req.outputData.length > 0) {\n first = req.outputData[0]!.data;\n endOfHeaders = first.indexOf(\"\\r\\n\\r\\n\") + 4;\n req.outputData[0]!.data = req._header + first.substring(endOfHeaders);\n }\n\n // Create a socket connection to the proxy server.\n let socket: net.Socket;\n if (this.proxy.protocol === \"https:\") {\n socket = tls.connect(this.connectOpts);\n } else {\n socket = net.connect(this.connectOpts);\n }\n\n // Wait for the socket's `connect` event, so that this `callback()`\n // function throws instead of the `http` request machinery. This is\n // important for i.e. `PacProxyAgent` which determines a failed proxy\n // connection via the `callback()` function throwing.\n await once(socket, \"connect\");\n\n return socket;\n }\n}\n\nfunction omit<T extends object, K extends [...(keyof T)[]]>(\n obj: T,\n ...keys: K\n): {\n [K2 in Exclude<keyof T, K[number]>]: T[K2];\n} {\n const ret = {} as {\n [K in keyof typeof obj]: (typeof obj)[K];\n };\n let key: keyof typeof obj;\n for (key in obj) {\n if (!keys.includes(key)) {\n ret[key] = obj[key];\n }\n }\n return ret;\n}\n"],"mappings":"iMA4DA,IAAa,EAAb,cAAwD,CAAM,CAC5D,OAAO,UAAY,CAAC,OAAQ,QAAQ,CAEpC,MAEA,aAEA,YAEA,YAAY,EAAkB,EAAmC,CAC/D,MAAM,EAAK,CACX,KAAK,MAAQ,OAAO,GAAU,SAAW,IAAI,EAAI,EAAM,CAAG,EAC1D,KAAK,aAAe,GAAM,SAAW,EAAE,CAGvC,IAAM,GAAQ,KAAK,MAAM,UAAY,KAAK,MAAM,MAAM,QACpD,WACA,GACD,CACK,EAAO,KAAK,MAAM,KACpB,OAAO,SAAS,KAAK,MAAM,KAAM,GAAG,CACpC,KAAK,MAAM,WAAa,SACtB,IACA,GACN,KAAK,YAAc,CACjB,GAAI,EAAO,EAAK,EAAM,UAAU,CAAG,KACnC,OACA,OACD,CAGH,WAAW,EAAkC,EAA8B,CACzE,EAAI,QAAU,KACd,KAAK,gBAAgB,EAAK,EAAK,CAI/B,MAAM,WAAW,EAAK,EAAK,CAG7B,gBACE,EACA,EACM,CACN,GAAM,CAAE,SAAU,KACZ,EAAW,EAAK,eAAiB,SAAW,QAC5C,EAAW,EAAI,UAAU,OAAO,EAAI,YACpC,EAAO,GAAG,EAAS,IAAI,MAAM,QAAQ,EAAS,CAAG,EAAS,KAAK,GAAG,CAAG,IACrE,EAAM,IAAI,EAAI,EAAI,KAAM,EAAK,CAC/B,EAAK,OAAS,KAChB,EAAI,KAAO,OAAO,EAAK,KAAK,EAK9B,EAAI,KAAO,OAAO,EAAI,CAItB,IAAMA,EACJ,OAAO,KAAK,cAAiB,WACzB,KAAK,cAAc,CACnB,CAAE,GAAG,KAAK,aAAc,CAC9B,GAAI,EAAM,UAAY,EAAM,SAAU,CACpC,IAAM,EAAO,GAAG,mBACd,EAAM,SACP,CAAC,GAAG,mBAAmB,EAAM,SAAS,GACvC,EAAQ,uBAAyB,SAAS,EAAO,KAAK,EAAK,CAAC,SAC1D,SACD,GAGH,AACE,EAAQ,sBAAsB,KAAK,UAAY,aAAe,QAEhE,IAAK,IAAM,KAAQ,OAAO,KAAK,EAAQ,CAAE,CACvC,IAAM,EAAQ,EAAQ,GAClB,GACF,EAAI,UAAU,EAAM,EAAM,EAKhC,MAAM,QACJ,EACA,EACqB,CACrB,EAAI,QAAU,KAET,EAAI,KAAK,SAAS,MAAM,EAC3B,KAAK,gBAAgB,EAAK,EAAK,CAMjC,IAAIC,EACAC,EAEJ,EAAI,iBAAiB,CACjB,EAAI,YAAc,EAAI,WAAW,OAAS,IAC5C,EAAQ,EAAI,WAAW,GAAI,KAC3B,EAAe,EAAM,QAAQ;;EAAW,CAAG,EAC3C,EAAI,WAAW,GAAI,KAAO,EAAI,QAAU,EAAM,UAAU,EAAa,EAIvE,IAAIC,EAaJ,MAZA,CAGE,EAHE,KAAK,MAAM,WAAa,SACjB,EAAI,QAAQ,KAAK,YAAY,CAE7B,EAAI,QAAQ,KAAK,YAAY,CAOxC,MAAM,EAAK,EAAQ,UAAU,CAEtB,IAIX,SAAS,EACP,EACA,GAAG,EAGH,CACA,IAAM,EAAM,EAAE,CAGVC,EACJ,IAAK,KAAO,EACL,EAAK,SAAS,EAAI,GACrB,EAAI,GAAO,EAAI,IAGnB,OAAO"}
|
package/dist/https-proxy.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./https
|
|
1
|
+
const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./parse-response.cjs`);let n=require(`node:net`);n=e.__toESM(n);let r=require(`node:buffer`),i=require(`node:tls`);i=e.__toESM(i);let a=require(`node:url`),o=require(`agent-base`),s=require(`node:assert`);s=e.__toESM(s);const c=e=>e.servername===void 0&&e.host&&!n.isIP(e.host)?{...e,servername:e.host}:e;var l=class extends o.Agent{static protocols=[`http`,`https`];proxy;proxyHeaders;connectOpts;constructor(e,t){super(t),this.options={path:void 0},this.proxy=typeof e==`string`?new a.URL(e):e,this.proxyHeaders=t?.headers??{};let n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),r=this.proxy.port?Number.parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={ALPNProtocols:[`http/1.1`],...t?d(t,`headers`):null,host:n,port:r}}async connect(e,a){let{proxy:o}=this;if(!a.host)throw TypeError(`No "host" provided`);let l;l=o.protocol===`https:`?i.connect(c(this.connectOpts)):n.connect(this.connectOpts);let f=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders},p=n.isIPv6(a.host)?`[${a.host}]`:a.host,m=`CONNECT ${p}:${a.port} HTTP/1.1\r\n`;if(o.username||o.password){let e=`${decodeURIComponent(o.username)}:${decodeURIComponent(o.password)}`;f[`Proxy-Authorization`]=`Basic ${r.Buffer.from(e).toString(`base64`)}`}f.Host=`${p}:${a.port}`,f[`Proxy-Connection`]||=this.keepAlive?`Keep-Alive`:`close`;for(let e of Object.keys(f))m+=`${e}: ${f[e]?.toString()}\r\n`;let h=t.parseProxyResponse(l);l.write(`${m}\r\n`);let{connect:g,buffered:_}=await h;if(e.emit(`proxyConnect`,g),this.emit(`proxyConnect`,g,e),g.statusCode===200)return e.once(`socket`,u),a.secureEndpoint?i.connect({...d(c(a),`host`,`path`,`port`),socket:l}):l;l.destroy();let v=new n.Socket({writable:!1});return v.readable=!0,e.once(`socket`,e=>{(0,s.default)(e.listenerCount(`data`)>0),e.push(_),e.push(null)}),v}};function u(e){e.resume()}function d(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}exports.HttpsProxyAgent=l;
|