nlcurl 0.12.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -15
- package/dist/cookies/psl-data.d.ts +2 -2
- package/dist/cookies/psl-data.d.ts.map +1 -1
- package/dist/cookies/psl-data.js +8 -2
- package/dist/cookies/psl-data.js.map +1 -1
- package/dist/dns/types.d.ts +0 -2
- package/dist/dns/types.d.ts.map +1 -1
- package/dist/dns/types.js.map +1 -1
- package/dist/fingerprints/extensions.d.ts +0 -6
- package/dist/fingerprints/extensions.d.ts.map +1 -1
- package/dist/fingerprints/extensions.js +0 -8
- package/dist/fingerprints/extensions.js.map +1 -1
- package/dist/fingerprints/ja3.d.ts +0 -14
- package/dist/fingerprints/ja3.d.ts.map +1 -1
- package/dist/fingerprints/ja3.js +0 -35
- package/dist/fingerprints/ja3.js.map +1 -1
- package/dist/http/h1/encoder.d.ts +0 -11
- package/dist/http/h1/encoder.d.ts.map +1 -1
- package/dist/http/h1/encoder.js +0 -51
- package/dist/http/h1/encoder.js.map +1 -1
- package/dist/http/h2/frames.d.ts +0 -19
- package/dist/http/h2/frames.d.ts.map +1 -1
- package/dist/http/h2/frames.js +0 -32
- package/dist/http/h2/frames.js.map +1 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -12
- package/dist/index.js.map +1 -1
- package/dist/tls/constants.d.ts +0 -7
- package/dist/tls/constants.d.ts.map +1 -1
- package/dist/tls/constants.js +0 -9
- package/dist/tls/constants.js.map +1 -1
- package/dist/tls/ech.d.ts.map +1 -1
- package/dist/tls/ech.js +0 -1
- package/dist/tls/ech.js.map +1 -1
- package/dist/tls/keylog.d.ts +0 -15
- package/dist/tls/keylog.d.ts.map +1 -1
- package/dist/tls/keylog.js +0 -19
- package/dist/tls/keylog.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +0 -11
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +0 -17
- package/dist/tls/stealth/handshake.js.map +1 -1
- package/package.json +3 -3
- package/dist/cache/groups.d.ts +0 -75
- package/dist/cache/groups.d.ts.map +0 -1
- package/dist/cache/groups.js +0 -118
- package/dist/cache/groups.js.map +0 -1
- package/dist/cache/no-vary-search.d.ts +0 -33
- package/dist/cache/no-vary-search.d.ts.map +0 -1
- package/dist/cache/no-vary-search.js +0 -148
- package/dist/cache/no-vary-search.js.map +0 -1
- package/dist/cache/range.d.ts +0 -120
- package/dist/cache/range.d.ts.map +0 -1
- package/dist/cache/range.js +0 -192
- package/dist/cache/range.js.map +0 -1
- package/dist/dns/dot-resolver.d.ts +0 -89
- package/dist/dns/dot-resolver.d.ts.map +0 -1
- package/dist/dns/dot-resolver.js +0 -166
- package/dist/dns/dot-resolver.js.map +0 -1
- package/dist/http/resumable-upload.d.ts +0 -76
- package/dist/http/resumable-upload.d.ts.map +0 -1
- package/dist/http/resumable-upload.js +0 -104
- package/dist/http/resumable-upload.js.map +0 -1
- package/dist/http/trailers.d.ts +0 -29
- package/dist/http/trailers.d.ts.map +0 -1
- package/dist/http/trailers.js +0 -57
- package/dist/http/trailers.js.map +0 -1
- package/dist/middleware/circuit-breaker.d.ts +0 -44
- package/dist/middleware/circuit-breaker.d.ts.map +0 -1
- package/dist/middleware/circuit-breaker.js +0 -96
- package/dist/middleware/circuit-breaker.js.map +0 -1
- package/dist/tls/ct.d.ts +0 -78
- package/dist/tls/ct.d.ts.map +0 -1
- package/dist/tls/ct.js +0 -175
- package/dist/tls/ct.js.map +0 -1
- package/dist/tls/early-data.d.ts +0 -45
- package/dist/tls/early-data.d.ts.map +0 -1
- package/dist/tls/early-data.js +0 -46
- package/dist/tls/early-data.js.map +0 -1
- package/dist/tls/ocsp.d.ts +0 -55
- package/dist/tls/ocsp.d.ts.map +0 -1
- package/dist/tls/ocsp.js +0 -131
- package/dist/tls/ocsp.js.map +0 -1
- package/dist/utils/dictionary-transport.d.ts +0 -97
- package/dist/utils/dictionary-transport.d.ts.map +0 -1
- package/dist/utils/dictionary-transport.js +0 -171
- package/dist/utils/dictionary-transport.js.map +0 -1
- package/dist/utils/tcp-fast-open.d.ts +0 -30
- package/dist/utils/tcp-fast-open.d.ts.map +0 -1
- package/dist/utils/tcp-fast-open.js +0 -36
- package/dist/utils/tcp-fast-open.js.map +0 -1
package/dist/tls/early-data.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/** Configuration for TLS 1.3 early data (0-RTT). */
|
|
2
|
-
export interface EarlyDataConfig {
|
|
3
|
-
/** Enable early data transmission. */
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
/** Maximum early data payload size in bytes. */
|
|
6
|
-
maxSize?: number;
|
|
7
|
-
/** Restrict early data to safe (idempotent) HTTP methods only. */
|
|
8
|
-
safeOnly?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/** Outcome of an early data (0-RTT) transmission attempt. */
|
|
11
|
-
export interface EarlyDataResult {
|
|
12
|
-
/** Whether the server accepted the early data. */
|
|
13
|
-
accepted: boolean;
|
|
14
|
-
/** Whether early data transmission was attempted. */
|
|
15
|
-
attempted: boolean;
|
|
16
|
-
/** Number of bytes sent as early data. */
|
|
17
|
-
bytesSent: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Determine whether early data can be sent for the given HTTP method.
|
|
21
|
-
*
|
|
22
|
-
* @param {string} method - HTTP method string.
|
|
23
|
-
* @param {EarlyDataConfig} [config] - Early data configuration.
|
|
24
|
-
* @returns {boolean} `true` if early data is permitted.
|
|
25
|
-
*/
|
|
26
|
-
export declare function canSendEarlyData(method: string, config?: EarlyDataConfig): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Prepare request data for 0-RTT transmission.
|
|
29
|
-
*
|
|
30
|
-
* @param {Buffer} requestData - Serialized request bytes.
|
|
31
|
-
* @param {EarlyDataConfig} [config] - Early data configuration.
|
|
32
|
-
* @returns {Buffer|null} Buffer to send as early data, or `null` if not applicable.
|
|
33
|
-
*/
|
|
34
|
-
export declare function prepareEarlyData(requestData: Buffer, config?: EarlyDataConfig): Buffer | null;
|
|
35
|
-
/**
|
|
36
|
-
* Check whether the server accepted early data on a connected socket.
|
|
37
|
-
*
|
|
38
|
-
* @param {{ alpnProtocol?: string | false; earlyData?: boolean }} socket - Socket with optional `earlyData` flag.
|
|
39
|
-
* @returns {EarlyDataResult} Early data acceptance result.
|
|
40
|
-
*/
|
|
41
|
-
export declare function checkEarlyDataAccepted(socket: {
|
|
42
|
-
alpnProtocol?: string | false;
|
|
43
|
-
earlyData?: boolean;
|
|
44
|
-
}): EarlyDataResult;
|
|
45
|
-
//# sourceMappingURL=early-data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"early-data.d.ts","sourceRoot":"","sources":["../../src/tls/early-data.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,qDAAqD;IACrD,SAAS,EAAE,OAAO,CAAC;IACnB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,OAAO,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAO7F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,eAAe,CAOtH"}
|
package/dist/tls/early-data.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const SAFE_EARLY_DATA_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
2
|
-
/**
|
|
3
|
-
* Determine whether early data can be sent for the given HTTP method.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} method - HTTP method string.
|
|
6
|
-
* @param {EarlyDataConfig} [config] - Early data configuration.
|
|
7
|
-
* @returns {boolean} `true` if early data is permitted.
|
|
8
|
-
*/
|
|
9
|
-
export function canSendEarlyData(method, config) {
|
|
10
|
-
if (!config?.enabled)
|
|
11
|
-
return false;
|
|
12
|
-
if (config.safeOnly !== false && !SAFE_EARLY_DATA_METHODS.has(method.toUpperCase())) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Prepare request data for 0-RTT transmission.
|
|
19
|
-
*
|
|
20
|
-
* @param {Buffer} requestData - Serialized request bytes.
|
|
21
|
-
* @param {EarlyDataConfig} [config] - Early data configuration.
|
|
22
|
-
* @returns {Buffer|null} Buffer to send as early data, or `null` if not applicable.
|
|
23
|
-
*/
|
|
24
|
-
export function prepareEarlyData(requestData, config) {
|
|
25
|
-
if (!config?.enabled)
|
|
26
|
-
return null;
|
|
27
|
-
const maxSize = config.maxSize ?? 16384;
|
|
28
|
-
if (requestData.length > maxSize)
|
|
29
|
-
return null;
|
|
30
|
-
return requestData;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check whether the server accepted early data on a connected socket.
|
|
34
|
-
*
|
|
35
|
-
* @param {{ alpnProtocol?: string | false; earlyData?: boolean }} socket - Socket with optional `earlyData` flag.
|
|
36
|
-
* @returns {EarlyDataResult} Early data acceptance result.
|
|
37
|
-
*/
|
|
38
|
-
export function checkEarlyDataAccepted(socket) {
|
|
39
|
-
const accepted = socket.earlyData === true;
|
|
40
|
-
return {
|
|
41
|
-
accepted,
|
|
42
|
-
attempted: true,
|
|
43
|
-
bytesSent: 0,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=early-data.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"early-data.js","sourceRoot":"","sources":["../../src/tls/early-data.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAsBpE;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAAwB;IACvE,IAAI,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACpF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB,EAAE,MAAwB;IAC5E,IAAI,CAAC,MAAM,EAAE,OAAO;QAAE,OAAO,IAAI,CAAC;IAElC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;IACxC,IAAI,WAAW,CAAC,MAAM,GAAG,OAAO;QAAE,OAAO,IAAI,CAAC;IAE9C,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA8D;IACnG,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC;IAC3C,OAAO;QACL,QAAQ;QACR,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,CAAC;KACb,CAAC;AACJ,CAAC"}
|
package/dist/tls/ocsp.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/** OCSP response status codes (RFC 6960). */
|
|
2
|
-
export declare enum OCSPResponseStatus {
|
|
3
|
-
SUCCESSFUL = 0,
|
|
4
|
-
MALFORMED_REQUEST = 1,
|
|
5
|
-
INTERNAL_ERROR = 2,
|
|
6
|
-
TRY_LATER = 3,
|
|
7
|
-
SIG_REQUIRED = 5,
|
|
8
|
-
UNAUTHORIZED = 6
|
|
9
|
-
}
|
|
10
|
-
/** Certificate revocation status from an OCSP response. */
|
|
11
|
-
export declare enum OCSPCertStatus {
|
|
12
|
-
GOOD = 0,
|
|
13
|
-
REVOKED = 1,
|
|
14
|
-
UNKNOWN = 2
|
|
15
|
-
}
|
|
16
|
-
/** Parsed result of an OCSP response. */
|
|
17
|
-
export interface OCSPResult {
|
|
18
|
-
/** Overall OCSP response status. */
|
|
19
|
-
status: OCSPResponseStatus;
|
|
20
|
-
/** Revocation status of the queried certificate. */
|
|
21
|
-
certStatus?: OCSPCertStatus;
|
|
22
|
-
/** Start of the validity window for this response. */
|
|
23
|
-
thisUpdate?: Date;
|
|
24
|
-
/** End of the validity window for this response. */
|
|
25
|
-
nextUpdate?: Date;
|
|
26
|
-
/** Time when the OCSP responder produced this response. */
|
|
27
|
-
producedAt?: Date;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Parse a DER-encoded OCSP response.
|
|
31
|
-
*
|
|
32
|
-
* @param {Buffer} derResponse - Raw DER bytes.
|
|
33
|
-
* @returns {OCSPResult} Parsed OCSP result.
|
|
34
|
-
*/
|
|
35
|
-
export declare function parseOCSPResponse(derResponse: Buffer): OCSPResult;
|
|
36
|
-
/**
|
|
37
|
-
* Check whether an OCSP result indicates the certificate is valid.
|
|
38
|
-
*
|
|
39
|
-
* @param {OCSPResult} result - Parsed OCSP result.
|
|
40
|
-
* @returns {boolean} `false` only if the certificate is explicitly revoked.
|
|
41
|
-
*/
|
|
42
|
-
export declare function isOCSPValid(result: OCSPResult): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Validate OCSP stapling on a TLS socket.
|
|
45
|
-
*
|
|
46
|
-
* @param {{ once(event: string, handler: (...args: any[]) => void): void }} socket - Socket emitter that fires an `"OCSPResponse"` event.
|
|
47
|
-
* @param {{ timeout?: number }} [options] - Optional timeout configuration.
|
|
48
|
-
* @returns {Promise<OCSPResult|undefined>} Parsed OCSP result, or `undefined` if no stapled response.
|
|
49
|
-
*/
|
|
50
|
-
export declare function validateOCSPStapling(socket: {
|
|
51
|
-
once(event: string, handler: (...args: any[]) => void): void;
|
|
52
|
-
}, options?: {
|
|
53
|
-
timeout?: number;
|
|
54
|
-
}): Promise<OCSPResult | undefined>;
|
|
55
|
-
//# sourceMappingURL=ocsp.d.ts.map
|
package/dist/tls/ocsp.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ocsp.d.ts","sourceRoot":"","sources":["../../src/tls/ocsp.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,oBAAY,kBAAkB;IAC5B,UAAU,IAAI;IACd,iBAAiB,IAAI;IACrB,cAAc,IAAI;IAClB,SAAS,IAAI;IACb,YAAY,IAAI;IAChB,YAAY,IAAI;CACjB;AAED,2DAA2D;AAC3D,oBAAY,cAAc;IACxB,IAAI,IAAI;IACR,OAAO,IAAI;IACX,OAAO,IAAI;CACZ;AAED,yCAAyC;AACzC,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,oDAAoD;IACpD,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,sDAAsD;IACtD,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,oDAAoD;IACpD,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAuCjE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAQvD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAA;CAAE,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAoB9K"}
|
package/dist/tls/ocsp.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/** OCSP response status codes (RFC 6960). */
|
|
2
|
-
export var OCSPResponseStatus;
|
|
3
|
-
(function (OCSPResponseStatus) {
|
|
4
|
-
OCSPResponseStatus[OCSPResponseStatus["SUCCESSFUL"] = 0] = "SUCCESSFUL";
|
|
5
|
-
OCSPResponseStatus[OCSPResponseStatus["MALFORMED_REQUEST"] = 1] = "MALFORMED_REQUEST";
|
|
6
|
-
OCSPResponseStatus[OCSPResponseStatus["INTERNAL_ERROR"] = 2] = "INTERNAL_ERROR";
|
|
7
|
-
OCSPResponseStatus[OCSPResponseStatus["TRY_LATER"] = 3] = "TRY_LATER";
|
|
8
|
-
OCSPResponseStatus[OCSPResponseStatus["SIG_REQUIRED"] = 5] = "SIG_REQUIRED";
|
|
9
|
-
OCSPResponseStatus[OCSPResponseStatus["UNAUTHORIZED"] = 6] = "UNAUTHORIZED";
|
|
10
|
-
})(OCSPResponseStatus || (OCSPResponseStatus = {}));
|
|
11
|
-
/** Certificate revocation status from an OCSP response. */
|
|
12
|
-
export var OCSPCertStatus;
|
|
13
|
-
(function (OCSPCertStatus) {
|
|
14
|
-
OCSPCertStatus[OCSPCertStatus["GOOD"] = 0] = "GOOD";
|
|
15
|
-
OCSPCertStatus[OCSPCertStatus["REVOKED"] = 1] = "REVOKED";
|
|
16
|
-
OCSPCertStatus[OCSPCertStatus["UNKNOWN"] = 2] = "UNKNOWN";
|
|
17
|
-
})(OCSPCertStatus || (OCSPCertStatus = {}));
|
|
18
|
-
/**
|
|
19
|
-
* Parse a DER-encoded OCSP response.
|
|
20
|
-
*
|
|
21
|
-
* @param {Buffer} derResponse - Raw DER bytes.
|
|
22
|
-
* @returns {OCSPResult} Parsed OCSP result.
|
|
23
|
-
*/
|
|
24
|
-
export function parseOCSPResponse(derResponse) {
|
|
25
|
-
if (!derResponse || derResponse.length < 3) {
|
|
26
|
-
return { status: OCSPResponseStatus.MALFORMED_REQUEST };
|
|
27
|
-
}
|
|
28
|
-
let offset = 0;
|
|
29
|
-
if (derResponse[offset] !== 0x30) {
|
|
30
|
-
return { status: OCSPResponseStatus.MALFORMED_REQUEST };
|
|
31
|
-
}
|
|
32
|
-
offset++;
|
|
33
|
-
const { value: outerLen, bytesRead: outerLenBytes } = readASN1Length(derResponse, offset);
|
|
34
|
-
if (outerLen === -1)
|
|
35
|
-
return { status: OCSPResponseStatus.MALFORMED_REQUEST };
|
|
36
|
-
offset += outerLenBytes;
|
|
37
|
-
if (derResponse[offset] !== 0x0a) {
|
|
38
|
-
return { status: OCSPResponseStatus.MALFORMED_REQUEST };
|
|
39
|
-
}
|
|
40
|
-
offset++;
|
|
41
|
-
const statusLen = derResponse[offset];
|
|
42
|
-
offset++;
|
|
43
|
-
if (statusLen !== 1 || offset >= derResponse.length) {
|
|
44
|
-
return { status: OCSPResponseStatus.MALFORMED_REQUEST };
|
|
45
|
-
}
|
|
46
|
-
const responseStatus = derResponse[offset];
|
|
47
|
-
offset++;
|
|
48
|
-
if (responseStatus !== OCSPResponseStatus.SUCCESSFUL) {
|
|
49
|
-
return { status: responseStatus };
|
|
50
|
-
}
|
|
51
|
-
const result = { status: responseStatus };
|
|
52
|
-
const certStatusResult = findCertStatus(derResponse, offset);
|
|
53
|
-
if (certStatusResult !== undefined) {
|
|
54
|
-
result.certStatus = certStatusResult;
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check whether an OCSP result indicates the certificate is valid.
|
|
60
|
-
*
|
|
61
|
-
* @param {OCSPResult} result - Parsed OCSP result.
|
|
62
|
-
* @returns {boolean} `false` only if the certificate is explicitly revoked.
|
|
63
|
-
*/
|
|
64
|
-
export function isOCSPValid(result) {
|
|
65
|
-
if (result.status !== OCSPResponseStatus.SUCCESSFUL) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
if (result.certStatus === OCSPCertStatus.REVOKED) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Validate OCSP stapling on a TLS socket.
|
|
75
|
-
*
|
|
76
|
-
* @param {{ once(event: string, handler: (...args: any[]) => void): void }} socket - Socket emitter that fires an `"OCSPResponse"` event.
|
|
77
|
-
* @param {{ timeout?: number }} [options] - Optional timeout configuration.
|
|
78
|
-
* @returns {Promise<OCSPResult|undefined>} Parsed OCSP result, or `undefined` if no stapled response.
|
|
79
|
-
*/
|
|
80
|
-
export function validateOCSPStapling(socket, options) {
|
|
81
|
-
return new Promise((resolve) => {
|
|
82
|
-
const timeout = options?.timeout ?? 5000;
|
|
83
|
-
let timer;
|
|
84
|
-
const onResponse = (response) => {
|
|
85
|
-
if (timer)
|
|
86
|
-
clearTimeout(timer);
|
|
87
|
-
if (!response || response.length === 0) {
|
|
88
|
-
resolve(undefined);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
resolve(parseOCSPResponse(response));
|
|
92
|
-
};
|
|
93
|
-
socket.once("OCSPResponse", onResponse);
|
|
94
|
-
timer = setTimeout(() => {
|
|
95
|
-
resolve(undefined);
|
|
96
|
-
}, timeout);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function readASN1Length(buf, offset) {
|
|
100
|
-
if (offset >= buf.length)
|
|
101
|
-
return { value: -1, bytesRead: 0 };
|
|
102
|
-
const first = buf[offset];
|
|
103
|
-
if (first < 0x80) {
|
|
104
|
-
return { value: first, bytesRead: 1 };
|
|
105
|
-
}
|
|
106
|
-
const numBytes = first & 0x7f;
|
|
107
|
-
if (numBytes === 0 || numBytes > 4 || offset + numBytes >= buf.length) {
|
|
108
|
-
return { value: -1, bytesRead: 0 };
|
|
109
|
-
}
|
|
110
|
-
let value = 0;
|
|
111
|
-
for (let i = 0; i < numBytes; i++) {
|
|
112
|
-
value = (value << 8) | buf[offset + 1 + i];
|
|
113
|
-
}
|
|
114
|
-
return { value, bytesRead: 1 + numBytes };
|
|
115
|
-
}
|
|
116
|
-
function findCertStatus(buf, startOffset) {
|
|
117
|
-
for (let i = startOffset; i < buf.length - 2; i++) {
|
|
118
|
-
const tag = buf[i];
|
|
119
|
-
if (tag === 0x80 && buf[i + 1] === 0x00) {
|
|
120
|
-
return OCSPCertStatus.GOOD;
|
|
121
|
-
}
|
|
122
|
-
if (tag === 0xa1) {
|
|
123
|
-
return OCSPCertStatus.REVOKED;
|
|
124
|
-
}
|
|
125
|
-
if (tag === 0x82 && buf[i + 1] === 0x00) {
|
|
126
|
-
return OCSPCertStatus.UNKNOWN;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=ocsp.js.map
|
package/dist/tls/ocsp.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ocsp.js","sourceRoot":"","sources":["../../src/tls/ocsp.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,CAAN,IAAY,kBAOX;AAPD,WAAY,kBAAkB;IAC5B,uEAAc,CAAA;IACd,qFAAqB,CAAA;IACrB,+EAAkB,CAAA;IAClB,qEAAa,CAAA;IACb,2EAAgB,CAAA;IAChB,2EAAgB,CAAA;AAClB,CAAC,EAPW,kBAAkB,KAAlB,kBAAkB,Q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C,GAAG,WAAW,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAE,CAAC;QACpB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACxC,OAAO,cAAc,CAAC,IAAI,CAAC;QAC7B,CAAC;QACD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,CAAC;QACD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACxC,OAAO,cAAc,CAAC,OAAO,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/** Stored compression dictionary with associated metadata. */
|
|
2
|
-
export interface CompressionDictionary {
|
|
3
|
-
/** SHA-256 hash of the dictionary data in structured field format. */
|
|
4
|
-
hash: string;
|
|
5
|
-
/** URL from which the dictionary was fetched. */
|
|
6
|
-
url: string;
|
|
7
|
-
/** Raw dictionary bytes. */
|
|
8
|
-
data: Buffer;
|
|
9
|
-
/** Timestamp (ms since epoch) when the dictionary was stored. */
|
|
10
|
-
storedAt: number;
|
|
11
|
-
/** URL match pattern from the `Use-As-Dictionary` header. */
|
|
12
|
-
matchPattern?: string;
|
|
13
|
-
/** Expiry timestamp (ms since epoch). */
|
|
14
|
-
expiresAt?: number;
|
|
15
|
-
}
|
|
16
|
-
/** Configuration for the compression dictionary store. */
|
|
17
|
-
export interface DictionaryConfig {
|
|
18
|
-
/** Maximum number of dictionaries to cache. */
|
|
19
|
-
maxEntries?: number;
|
|
20
|
-
/** Maximum individual dictionary size in bytes. */
|
|
21
|
-
maxDictionarySize?: number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Parse a `Use-As-Dictionary` response header.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} header - Raw header value.
|
|
27
|
-
* @returns {{ match?: string; matchDest?: string[]; id?: string } | null} Parsed fields, or `null` if the header is empty.
|
|
28
|
-
*/
|
|
29
|
-
export declare function parseUseAsDictionary(header: string): {
|
|
30
|
-
match?: string;
|
|
31
|
-
matchDest?: string[];
|
|
32
|
-
id?: string;
|
|
33
|
-
} | null;
|
|
34
|
-
/**
|
|
35
|
-
* Compute the SHA-256 structured hash of dictionary data.
|
|
36
|
-
*
|
|
37
|
-
* @param {Buffer} data - Raw dictionary bytes.
|
|
38
|
-
* @returns {string} Hash string in structured field byte-sequence format.
|
|
39
|
-
*/
|
|
40
|
-
export declare function computeDictionaryHash(data: Buffer): string;
|
|
41
|
-
/**
|
|
42
|
-
* Build an `Available-Dictionary` request header value.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} hash - Dictionary hash.
|
|
45
|
-
* @returns {string} Header value string.
|
|
46
|
-
*/
|
|
47
|
-
export declare function buildAvailableDictionaryHeader(hash: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Append dictionary-based encodings to an `Accept-Encoding` header.
|
|
50
|
-
*
|
|
51
|
-
* @param {string} [existingEncoding] - Current `Accept-Encoding` value.
|
|
52
|
-
* @returns {string} Updated encoding string with `dcb` and `dcz` appended.
|
|
53
|
-
*/
|
|
54
|
-
export declare function buildDictionaryAcceptEncoding(existingEncoding?: string): string;
|
|
55
|
-
/** Cache of compression dictionaries for shared dictionary transport. */
|
|
56
|
-
export declare class DictionaryStore {
|
|
57
|
-
private readonly dictionaries;
|
|
58
|
-
private readonly maxEntries;
|
|
59
|
-
private readonly maxDictionarySize;
|
|
60
|
-
/**
|
|
61
|
-
* Create a new dictionary store.
|
|
62
|
-
*
|
|
63
|
-
* @param {DictionaryConfig} [config] - Cache size and dictionary size limits.
|
|
64
|
-
*/
|
|
65
|
-
constructor(config?: DictionaryConfig);
|
|
66
|
-
/**
|
|
67
|
-
* Store a dictionary response.
|
|
68
|
-
*
|
|
69
|
-
* @param {string} url - URL the dictionary was fetched from.
|
|
70
|
-
* @param {Buffer} data - Raw dictionary bytes.
|
|
71
|
-
* @param {{ match?: string; id?: string }} [metadata] - Match pattern and ID from the response header.
|
|
72
|
-
* @param {number} [maxAge] - Maximum age in seconds.
|
|
73
|
-
*/
|
|
74
|
-
store(url: string, data: Buffer, metadata?: {
|
|
75
|
-
match?: string;
|
|
76
|
-
id?: string;
|
|
77
|
-
}, maxAge?: number): void;
|
|
78
|
-
/**
|
|
79
|
-
* Find a dictionary whose match pattern covers the given request URL.
|
|
80
|
-
*
|
|
81
|
-
* @param {string} requestUrl - URL being requested.
|
|
82
|
-
* @returns {CompressionDictionary | undefined} Matching dictionary, or `undefined` if none found.
|
|
83
|
-
*/
|
|
84
|
-
findForUrl(requestUrl: string): CompressionDictionary | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Retrieve a dictionary by its hash.
|
|
87
|
-
*
|
|
88
|
-
* @param {string} hash - Dictionary hash string.
|
|
89
|
-
* @returns {CompressionDictionary | undefined} Dictionary entry, or `undefined` if not found.
|
|
90
|
-
*/
|
|
91
|
-
getByHash(hash: string): CompressionDictionary | undefined;
|
|
92
|
-
/** Number of dictionaries currently stored. */
|
|
93
|
-
get size(): number;
|
|
94
|
-
/** Remove all stored dictionaries. */
|
|
95
|
-
clear(): void;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=dictionary-transport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary-transport.d.ts","sourceRoot":"","sources":["../../src/utils/dictionary-transport.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,4BAA4B;IAC5B,IAAI,EAAE,M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KG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAmBjE;;;;;OAKG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAI1D,+CAA+C;IAC/C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,sCAAsC;IACtC,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
const DICT_MATCH_REGEX = /match="([^"]+)"/;
|
|
3
|
-
const DICT_DEST_REGEX = /match-dest=\(([^)]*)\)/;
|
|
4
|
-
const DICT_ID_REGEX = /id="([^"]+)"/;
|
|
5
|
-
/**
|
|
6
|
-
* Parse a `Use-As-Dictionary` response header.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} header - Raw header value.
|
|
9
|
-
* @returns {{ match?: string; matchDest?: string[]; id?: string } | null} Parsed fields, or `null` if the header is empty.
|
|
10
|
-
*/
|
|
11
|
-
export function parseUseAsDictionary(header) {
|
|
12
|
-
if (!header)
|
|
13
|
-
return null;
|
|
14
|
-
const result = {};
|
|
15
|
-
const matchMatch = header.match(DICT_MATCH_REGEX);
|
|
16
|
-
if (matchMatch) {
|
|
17
|
-
result.match = matchMatch[1];
|
|
18
|
-
}
|
|
19
|
-
const destMatch = header.match(DICT_DEST_REGEX);
|
|
20
|
-
if (destMatch) {
|
|
21
|
-
result.matchDest = destMatch[1]
|
|
22
|
-
.split(/\s+/)
|
|
23
|
-
.map((s) => s.replace(/"/g, ""))
|
|
24
|
-
.filter(Boolean);
|
|
25
|
-
}
|
|
26
|
-
const idMatch = header.match(DICT_ID_REGEX);
|
|
27
|
-
if (idMatch) {
|
|
28
|
-
result.id = idMatch[1];
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Compute the SHA-256 structured hash of dictionary data.
|
|
34
|
-
*
|
|
35
|
-
* @param {Buffer} data - Raw dictionary bytes.
|
|
36
|
-
* @returns {string} Hash string in structured field byte-sequence format.
|
|
37
|
-
*/
|
|
38
|
-
export function computeDictionaryHash(data) {
|
|
39
|
-
const hash = createHash("sha256").update(data).digest("base64");
|
|
40
|
-
return `:${hash}:`;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Build an `Available-Dictionary` request header value.
|
|
44
|
-
*
|
|
45
|
-
* @param {string} hash - Dictionary hash.
|
|
46
|
-
* @returns {string} Header value string.
|
|
47
|
-
*/
|
|
48
|
-
export function buildAvailableDictionaryHeader(hash) {
|
|
49
|
-
return hash;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Append dictionary-based encodings to an `Accept-Encoding` header.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} [existingEncoding] - Current `Accept-Encoding` value.
|
|
55
|
-
* @returns {string} Updated encoding string with `dcb` and `dcz` appended.
|
|
56
|
-
*/
|
|
57
|
-
export function buildDictionaryAcceptEncoding(existingEncoding) {
|
|
58
|
-
const base = existingEncoding ?? "gzip, deflate, br";
|
|
59
|
-
const encodings = base.split(",").map((s) => s.trim());
|
|
60
|
-
if (!encodings.includes("dcb"))
|
|
61
|
-
encodings.push("dcb");
|
|
62
|
-
if (!encodings.includes("dcz"))
|
|
63
|
-
encodings.push("dcz");
|
|
64
|
-
return encodings.join(", ");
|
|
65
|
-
}
|
|
66
|
-
/** Cache of compression dictionaries for shared dictionary transport. */
|
|
67
|
-
export class DictionaryStore {
|
|
68
|
-
dictionaries = new Map();
|
|
69
|
-
maxEntries;
|
|
70
|
-
maxDictionarySize;
|
|
71
|
-
/**
|
|
72
|
-
* Create a new dictionary store.
|
|
73
|
-
*
|
|
74
|
-
* @param {DictionaryConfig} [config] - Cache size and dictionary size limits.
|
|
75
|
-
*/
|
|
76
|
-
constructor(config) {
|
|
77
|
-
this.maxEntries = config?.maxEntries ?? 50;
|
|
78
|
-
this.maxDictionarySize = config?.maxDictionarySize ?? 10 * 1024 * 1024;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Store a dictionary response.
|
|
82
|
-
*
|
|
83
|
-
* @param {string} url - URL the dictionary was fetched from.
|
|
84
|
-
* @param {Buffer} data - Raw dictionary bytes.
|
|
85
|
-
* @param {{ match?: string; id?: string }} [metadata] - Match pattern and ID from the response header.
|
|
86
|
-
* @param {number} [maxAge] - Maximum age in seconds.
|
|
87
|
-
*/
|
|
88
|
-
store(url, data, metadata, maxAge) {
|
|
89
|
-
if (data.length > this.maxDictionarySize)
|
|
90
|
-
return;
|
|
91
|
-
if (this.dictionaries.size >= this.maxEntries) {
|
|
92
|
-
let oldest;
|
|
93
|
-
let oldestTime = Infinity;
|
|
94
|
-
for (const [key, entry] of this.dictionaries) {
|
|
95
|
-
if (entry.storedAt < oldestTime) {
|
|
96
|
-
oldestTime = entry.storedAt;
|
|
97
|
-
oldest = key;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (oldest)
|
|
101
|
-
this.dictionaries.delete(oldest);
|
|
102
|
-
}
|
|
103
|
-
const hash = computeDictionaryHash(data);
|
|
104
|
-
const now = Date.now();
|
|
105
|
-
this.dictionaries.set(hash, {
|
|
106
|
-
hash,
|
|
107
|
-
url,
|
|
108
|
-
data,
|
|
109
|
-
storedAt: now,
|
|
110
|
-
matchPattern: metadata?.match,
|
|
111
|
-
expiresAt: maxAge ? now + maxAge * 1000 : undefined,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Find a dictionary whose match pattern covers the given request URL.
|
|
116
|
-
*
|
|
117
|
-
* @param {string} requestUrl - URL being requested.
|
|
118
|
-
* @returns {CompressionDictionary | undefined} Matching dictionary, or `undefined` if none found.
|
|
119
|
-
*/
|
|
120
|
-
findForUrl(requestUrl) {
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
for (const dict of this.dictionaries.values()) {
|
|
123
|
-
if (dict.expiresAt && dict.expiresAt < now) {
|
|
124
|
-
this.dictionaries.delete(dict.hash);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (dict.matchPattern) {
|
|
128
|
-
if (matchesPattern(requestUrl, dict.matchPattern, dict.url)) {
|
|
129
|
-
return dict;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Retrieve a dictionary by its hash.
|
|
137
|
-
*
|
|
138
|
-
* @param {string} hash - Dictionary hash string.
|
|
139
|
-
* @returns {CompressionDictionary | undefined} Dictionary entry, or `undefined` if not found.
|
|
140
|
-
*/
|
|
141
|
-
getByHash(hash) {
|
|
142
|
-
return this.dictionaries.get(hash);
|
|
143
|
-
}
|
|
144
|
-
/** Number of dictionaries currently stored. */
|
|
145
|
-
get size() {
|
|
146
|
-
return this.dictionaries.size;
|
|
147
|
-
}
|
|
148
|
-
/** Remove all stored dictionaries. */
|
|
149
|
-
clear() {
|
|
150
|
-
this.dictionaries.clear();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function matchesPattern(requestUrl, pattern, dictionaryUrl) {
|
|
154
|
-
try {
|
|
155
|
-
const dictBase = new URL(dictionaryUrl);
|
|
156
|
-
const reqUrl = new URL(requestUrl);
|
|
157
|
-
if (reqUrl.origin !== dictBase.origin)
|
|
158
|
-
return false;
|
|
159
|
-
if (pattern === "*" || pattern === "/*")
|
|
160
|
-
return true;
|
|
161
|
-
if (pattern.endsWith("*")) {
|
|
162
|
-
const prefix = pattern.slice(0, -1);
|
|
163
|
-
return reqUrl.pathname.startsWith(prefix);
|
|
164
|
-
}
|
|
165
|
-
return reqUrl.pathname === pattern;
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=dictionary-transport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary-transport.js","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*
|
|
4
|
-
* @returns {boolean} `true` on Linux and macOS.
|
|
5
|
-
*/
|
|
6
|
-
export declare function isTFOSupported(): boolean;
|
|
7
|
-
/** Configuration for TCP Fast Open (TFO). */
|
|
8
|
-
export interface TFOOptions {
|
|
9
|
-
/** Enable TCP Fast Open for the connection. */
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
/** Data to send during the TCP handshake. */
|
|
12
|
-
connectData?: Buffer;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Build socket creation options for TCP Fast Open.
|
|
16
|
-
*
|
|
17
|
-
* @param {TFOOptions} [tfo] - TFO configuration.
|
|
18
|
-
* @returns {Record<string, unknown>} Options object to merge into socket creation.
|
|
19
|
-
*/
|
|
20
|
-
export declare function buildTFOSocketOptions(tfo?: TFOOptions): Record<string, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Return the current TFO support status and platform name.
|
|
23
|
-
*
|
|
24
|
-
* @returns {{ supported: boolean; platform: string }} Object with `supported` flag and `platform` string.
|
|
25
|
-
*/
|
|
26
|
-
export declare function getTFOStatus(): {
|
|
27
|
-
supported: boolean;
|
|
28
|
-
platform: string;
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=tcp-fast-open.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-fast-open.d.ts","sourceRoot":"","sources":["../../src/utils/tcp-fast-open.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAGxC;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQ/E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAKvE"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { platform } from "node:os";
|
|
2
|
-
/**
|
|
3
|
-
* Check whether TCP Fast Open is supported on the current platform.
|
|
4
|
-
*
|
|
5
|
-
* @returns {boolean} `true` on Linux and macOS.
|
|
6
|
-
*/
|
|
7
|
-
export function isTFOSupported() {
|
|
8
|
-
const os = platform();
|
|
9
|
-
return os === "linux" || os === "darwin";
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Build socket creation options for TCP Fast Open.
|
|
13
|
-
*
|
|
14
|
-
* @param {TFOOptions} [tfo] - TFO configuration.
|
|
15
|
-
* @returns {Record<string, unknown>} Options object to merge into socket creation.
|
|
16
|
-
*/
|
|
17
|
-
export function buildTFOSocketOptions(tfo) {
|
|
18
|
-
if (!tfo?.enabled || !isTFOSupported()) {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
fastOpen: true,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Return the current TFO support status and platform name.
|
|
27
|
-
*
|
|
28
|
-
* @returns {{ supported: boolean; platform: string }} Object with `supported` flag and `platform` string.
|
|
29
|
-
*/
|
|
30
|
-
export function getTFOStatus() {
|
|
31
|
-
return {
|
|
32
|
-
supported: isTFOSupported(),
|
|
33
|
-
platform: platform(),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=tcp-fast-open.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-fast-open.js","sourceRoot":"","sources":["../../src/utils/tcp-fast-open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,QAAQ,CAAC;AAC3C,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAgB;IACpD,IAAI,CAAC,GAAG,EAAE,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO;QACL,SAAS,EAAE,cAAc,EAAE;QAC3B,QAAQ,EAAE,QAAQ,EAAE;KACrB,CAAC;AACJ,CAAC"}
|