@mswjs/interceptors 0.42.3 → 0.42.4
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/lib/browser/interceptors/WebSocket/index.js +14 -1
- package/lib/browser/interceptors/WebSocket/index.js.map +1 -1
- package/lib/node/{batch-interceptor-ByEZVih3.js → batch-interceptor-DMOfd-9x.js} +2 -2
- package/lib/node/{batch-interceptor-ByEZVih3.js.map → batch-interceptor-DMOfd-9x.js.map} +1 -1
- package/lib/node/buffer-utils-B4FUq-l2.js +17 -0
- package/lib/node/buffer-utils-B4FUq-l2.js.map +1 -0
- package/lib/node/create-request-id-DHo-fRTV.js +14 -0
- package/lib/node/create-request-id-DHo-fRTV.js.map +1 -0
- package/lib/node/{fetch-utils-Dw1PsmtX.js → fetch-utils-Tm5LbwBe.js} +3 -14
- package/lib/node/{fetch-utils-Dw1PsmtX.js.map → fetch-utils-Tm5LbwBe.js.map} +1 -1
- package/lib/node/{has-configurable-global-BU1sT1u4.js → has-configurable-global-CT6-QYdg.js} +2 -2
- package/lib/node/{has-configurable-global-BU1sT1u4.js.map → has-configurable-global-CT6-QYdg.js.map} +1 -1
- package/lib/node/index.d.ts +2 -243
- package/lib/node/index.js +6 -25
- package/lib/node/index.js.map +1 -1
- package/lib/node/{buffer-utils-BvPY1Tc-.js → interceptor-C8qRPjxG.js} +2 -16
- package/lib/node/interceptor-C8qRPjxG.js.map +1 -0
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/WebSocket/index.d.ts +2 -0
- package/lib/node/interceptors/WebSocket/index.js +635 -0
- package/lib/node/interceptors/WebSocket/index.js.map +1 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js +5 -5
- package/lib/node/interceptors/fetch/node.js +5 -5
- package/lib/node/interceptors/http/index.js +2 -2
- package/lib/node/interceptors/net/index.d.ts +9 -0
- package/lib/node/interceptors/net/index.js +1 -1
- package/lib/node/{net-Ca8p1rIe.js → net-DkiHxhQF.js} +43 -79
- package/lib/node/net-DkiHxhQF.js.map +1 -0
- package/lib/node/patches-registry-DxR5TEc-.js +76 -0
- package/lib/node/patches-registry-DxR5TEc-.js.map +1 -0
- package/lib/node/remote-http-interceptor.js +4 -4
- package/lib/node/resolve-web-socket-url-CSvNPLGi.js +25 -0
- package/lib/node/resolve-web-socket-url-CSvNPLGi.js.map +1 -0
- package/lib/node/{source-CIgPng7r.js → source-BFZ6wg4P.js} +95 -38
- package/lib/node/source-BFZ6wg4P.js.map +1 -0
- package/lib/node/websocket-CC0nB0md.d.ts +285 -0
- package/package.json +5 -2
- package/src/interceptors/WebSocket/index.ts +4 -1
- package/src/interceptors/http/http-parser/index.ts +9 -1
- package/src/interceptors/http/http-parser.ts +21 -4
- package/src/interceptors/http/source.ts +71 -3
- package/src/interceptors/net/index.ts +39 -12
- package/src/interceptors/net/socket-controller.ts +34 -9
- package/src/utils/internal-connection.ts +22 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js.map +0 -1
- package/lib/node/net-Ca8p1rIe.js.map +0 -1
- package/lib/node/source-CIgPng7r.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-BFZ6wg4P.js","names":["constants","#checkError","#upgrade","#requestBodyStream","#status","#responseBodyStream","#modifyHttpHeaders"],"sources":["../../src/request-context.ts","../../src/interceptors/http/forward-events.ts","../../src/events/http.ts","../../src/interceptors/net/utils/connection-options-to-url.ts","../../src/interceptors/http/http-parser/llhttp/constants.cjs","../../src/interceptors/http/http-parser/index.ts","../../src/interceptors/http/http-parser.ts","../../src/utils/is-node-like-error.ts","../../src/utils/handle-request.ts","../../src/interceptors/http/source.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\nimport type { Logger } from './utils/logger'\n\ninterface RequestContext {\n initiator: unknown\n logger?: Logger\n transformRequest?: (request: Request) => Request\n}\n\nexport const requestContext = new AsyncLocalStorage<RequestContext>()\n\nexport function runInRequestContext<T>(callback: () => T, logger?: Logger): T {\n /**\n * @note Never shadow an existing request context. Nested calls\n * (e.g. a patched entry point re-entered synchronously, or a request\n * made within the fetch/XMLHttpRequest interceptor context) must run\n * within the parent context so the sockets they create capture it.\n */\n if (requestContext.getStore()) {\n return callback()\n }\n\n /**\n * @note The initiator is the callback's return value (e.g. the\n * \"ClientRequest\" instance), so it cannot be known before running\n * the callback. The context is mutated in place once the callback\n * returns; readers hold the context object by reference and sample\n * \"initiator\" only after the request has been written.\n */\n const context: RequestContext = {\n initiator: undefined,\n logger,\n }\n\n return requestContext.run(context, () => {\n const initiator = callback()\n context.initiator = initiator\n return initiator\n })\n}\n","import { type Emitter } from 'rettime'\nimport {\n type HttpRequestEventMap,\n type HttpResponseEvent,\n} from '#/src/events/http'\nimport { type Interceptor } from '#/src/interceptor'\nimport { type DisposableSubscription } from '#/src/disposable'\nimport { createLogger } from '#/src/utils/logger'\n\nconst logger = createLogger('http-request')\n\ninterface ForwardHttpEventsOptions {\n source: Interceptor<HttpRequestEventMap>\n emitter: Emitter<HttpRequestEventMap>\n predicate: (initiator: unknown) => boolean\n responsePredicate?: (event: HttpResponseEvent) => boolean\n}\n\nexport function forwardHttpEvents(\n options: ForwardHttpEventsOptions\n): DisposableSubscription {\n const controller = new AbortController()\n const { source, emitter, predicate, responsePredicate } = options\n\n source.on(\n 'request',\n async (event) => {\n if (predicate(event.initiator)) {\n logger.verbose('forwarding \"request\" event %o', {\n requestId: event.requestId,\n })\n await emitter.emitAsPromise(event)\n }\n },\n {\n signal: controller.signal,\n }\n )\n\n const responseListener: Emitter.Listener<\n Emitter<HttpRequestEventMap>,\n 'response'\n > = async (event) => {\n if (\n predicate(event.initiator) &&\n (responsePredicate == null || responsePredicate(event))\n ) {\n logger.verbose('forwarding \"response\" event %o', {\n requestId: event.requestId,\n responseType: event.responseType,\n })\n await emitter.emitAsPromise(event)\n }\n }\n\n const unhandledExceptionListener: Emitter.Listener<\n Emitter<HttpRequestEventMap>,\n 'unhandledException'\n > = async (event) => {\n if (predicate(event.initiator)) {\n logger.verbose('forwarding \"unhandledException\" event %o', {\n requestId: event.requestId,\n })\n await emitter.emitAsPromise(event)\n }\n }\n\n const addResponseListener = (): void => {\n if (!source.listeners('response').includes(responseListener)) {\n source.on('response', responseListener, {\n signal: controller.signal,\n })\n }\n }\n\n const addUnhandledExceptionListener = (): void => {\n if (\n !source\n .listeners('unhandledException')\n .includes(unhandledExceptionListener)\n ) {\n source.on('unhandledException', unhandledExceptionListener, {\n signal: controller.signal,\n })\n }\n }\n\n if (emitter.listenerCount('response') > 0) {\n addResponseListener()\n }\n\n if (emitter.listenerCount('unhandledException') > 0) {\n addUnhandledExceptionListener()\n }\n\n emitter.hooks.on(\n 'newListener',\n (type) => {\n if (type === 'response') {\n addResponseListener()\n }\n\n if (type === 'unhandledException') {\n addUnhandledExceptionListener()\n }\n },\n {\n signal: controller.signal,\n persist: true,\n }\n )\n\n emitter.hooks.on(\n 'removeListener',\n (type) => {\n if (type === 'response' && emitter.listenerCount('response') === 0) {\n source.removeListener('response', responseListener)\n }\n\n if (\n type === 'unhandledException' &&\n emitter.listenerCount('unhandledException') === 0\n ) {\n source.removeListener(\n 'unhandledException',\n unhandledExceptionListener\n )\n }\n },\n {\n signal: controller.signal,\n persist: true,\n }\n )\n\n return () => {\n controller.abort()\n }\n}\n","import { TypedEvent } from 'rettime'\nimport type { RequestController } from '../request-controller'\n\nexport interface HttpRequestEventData {\n request: Request\n requestId: string\n initiator: unknown\n controller: RequestController\n}\n\nexport class HttpRequestEvent<\n DataType extends HttpRequestEventData = HttpRequestEventData,\n> extends TypedEvent<DataType, void, 'request'> {\n public request: Request\n public requestId: string\n public initiator: unknown\n public controller: RequestController\n\n constructor(data: DataType) {\n super(...(['request', {}] as any))\n\n this.request = data.request\n this.requestId = data.requestId\n this.initiator = data.initiator\n this.controller = data.controller\n }\n}\n\nexport type HttpResponseType = 'mock' | 'original'\n\ninterface HttpResponseEventData {\n response: Response\n responseType: HttpResponseType\n request: Request\n requestId: string\n initiator: unknown\n}\n\nexport class HttpResponseEvent<\n DataType extends HttpResponseEventData = HttpResponseEventData,\n> extends TypedEvent<DataType, void, 'response'> {\n public response: Response\n public responseType: HttpResponseType\n public request: Request\n public requestId: string\n public initiator: unknown\n\n constructor(data: DataType) {\n super(...(['response', {}] as any))\n\n this.response = data.response\n this.responseType = data.responseType\n this.request = data.request\n this.requestId = data.requestId\n this.initiator = data.initiator\n }\n}\n\ninterface UnhandledHttpExceptionEventData {\n error: unknown\n request: Request\n requestId: string\n initiator: unknown\n controller: RequestController\n}\n\nexport class UnhandledHttpException<\n DataType extends UnhandledHttpExceptionEventData =\n UnhandledHttpExceptionEventData,\n> extends TypedEvent<DataType, void, 'unhandledException'> {\n public error: unknown\n public request: Request\n public requestId: string\n public initiator: unknown\n public controller: RequestController\n\n constructor(data: DataType) {\n super(...(['unhandledException', {}] as any))\n\n this.error = data.error\n this.request = data.request\n this.requestId = data.requestId\n this.initiator = data.initiator\n this.controller = data.controller\n }\n}\n\nexport type HttpRequestEventMap = {\n request: HttpRequestEvent\n response: HttpResponseEvent\n unhandledException: UnhandledHttpException\n}\n","import net from 'node:net'\nimport tls from 'node:tls'\nimport { NetworkConnectionOptions } from './normalize-net-connect-args'\n\n/**\n * Creates a `URL` instance out of the `net.connect()` options.\n * @note This implies that the passed connection is an HTTP connection.\n */\nexport function connectionOptionsToUrl(\n options: NetworkConnectionOptions,\n socket: net.Socket\n): URL {\n const isIPv6 = net.isIPv6(options.host || '')\n const protocol =\n socket instanceof tls.TLSSocket\n ? 'https:'\n : getProtocolByConnectionOptions(options)\n const host = options.host || 'localhost'\n\n const url = new URL(`${protocol}//${isIPv6 ? `[${host}]` : host}`)\n\n if (options.path) {\n url.pathname = options.path\n }\n\n if (options.port) {\n url.port = options.port.toString()\n }\n\n if (options.auth) {\n const [username, password] = options.auth.split(':')\n /**\n * Authentication options are provided as plain values.\n * Encode them to form a valid URL.\n * @see https://github.com/nodejs/node/blob/f3adc11e37b8bfaaa026ea85c1cf22e3a0e29ae9/lib/internal/url.js#L1452\n */\n url.username = encodeURIComponent(username)\n url.password = encodeURIComponent(password)\n }\n\n return url\n}\n\nfunction getProtocolByConnectionOptions(\n options: NetworkConnectionOptions\n): 'https:' | 'http:' | (string & {}) {\n if (options.protocol) {\n return options.protocol\n }\n\n if (options.port === 443) {\n return 'https:'\n }\n\n return 'http:'\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.SPECIAL_HEADERS = exports.MINOR = exports.MAJOR = exports.QDTEXT = exports.CONNECTION_TOKEN_CHARS = exports.RELAXED_HEADER_CHARS = exports.HEADER_CHARS = exports.HTAB_SP_VCHAR_OBS_TEXT = exports.SP = exports.HTAB = exports.TOKEN = exports.HEX = exports.URL_CHAR = exports.USERINFO_CHARS = exports.MARK = exports.ALPHANUM = exports.DIGIT = exports.HEX_MAP = exports.NUM_MAP = exports.ALPHA = exports.METHODS = exports.METHODS_HTTP = exports.METHODS_HTTP2 = exports.METHODS_HTTP1 = exports.METHODS_RTSP = exports.METHODS_RAOP = exports.METHODS_AIRPLAY = exports.METHODS_ICECAST = exports.METHODS_NON_STANDARD = exports.METHODS_CALDAV = exports.METHODS_UPNP = exports.METHODS_SUBVERSION = exports.METHODS_WEBDAV = exports.METHODS_BASIC_HTTP = exports.METHODS_HTTP1_HEAD = exports.HEADER_STATE = exports.FINISH = exports.STATUSES = exports.LENIENT_FLAGS = exports.FLAGS = exports.TYPE = exports.ERROR = void 0;\nexports.ERROR = {\n OK: 0,\n INTERNAL: 1,\n STRICT: 2,\n CR_EXPECTED: 25,\n LF_EXPECTED: 3,\n UNEXPECTED_CONTENT_LENGTH: 4,\n UNEXPECTED_SPACE: 30,\n CLOSED_CONNECTION: 5,\n INVALID_METHOD: 6,\n INVALID_URL: 7,\n INVALID_CONSTANT: 8,\n INVALID_VERSION: 9,\n INVALID_HEADER_TOKEN: 10,\n INVALID_CONTENT_LENGTH: 11,\n INVALID_CHUNK_SIZE: 12,\n INVALID_STATUS: 13,\n INVALID_EOF_STATE: 14,\n INVALID_TRANSFER_ENCODING: 15,\n CB_MESSAGE_BEGIN: 16,\n CB_HEADERS_COMPLETE: 17,\n CB_MESSAGE_COMPLETE: 18,\n CB_CHUNK_HEADER: 19,\n CB_CHUNK_COMPLETE: 20,\n PAUSED: 21,\n PAUSED_UPGRADE: 22,\n PAUSED_H2_UPGRADE: 23,\n USER: 24,\n CB_URL_COMPLETE: 26,\n CB_STATUS_COMPLETE: 27,\n CB_METHOD_COMPLETE: 32,\n CB_VERSION_COMPLETE: 33,\n CB_HEADER_FIELD_COMPLETE: 28,\n CB_HEADER_VALUE_COMPLETE: 29,\n CB_CHUNK_EXTENSION_NAME_COMPLETE: 34,\n CB_CHUNK_EXTENSION_VALUE_COMPLETE: 35,\n CB_RESET: 31,\n CB_PROTOCOL_COMPLETE: 38,\n};\nexports.TYPE = {\n BOTH: 0, // default\n REQUEST: 1,\n RESPONSE: 2,\n};\nexports.FLAGS = {\n CONNECTION_KEEP_ALIVE: 1 << 0,\n CONNECTION_CLOSE: 1 << 1,\n CONNECTION_UPGRADE: 1 << 2,\n CHUNKED: 1 << 3,\n UPGRADE: 1 << 4,\n CONTENT_LENGTH: 1 << 5,\n SKIPBODY: 1 << 6,\n TRAILING: 1 << 7,\n // 1 << 8 is unused\n TRANSFER_ENCODING: 1 << 9,\n};\nexports.LENIENT_FLAGS = {\n HEADERS: 1 << 0,\n CHUNKED_LENGTH: 1 << 1,\n KEEP_ALIVE: 1 << 2,\n TRANSFER_ENCODING: 1 << 3,\n VERSION: 1 << 4,\n DATA_AFTER_CLOSE: 1 << 5,\n OPTIONAL_LF_AFTER_CR: 1 << 6,\n OPTIONAL_CRLF_AFTER_CHUNK: 1 << 7,\n OPTIONAL_CR_BEFORE_LF: 1 << 8,\n SPACES_AFTER_CHUNK_SIZE: 1 << 9,\n HEADER_VALUE_RELAXED: 1 << 10,\n};\nexports.STATUSES = {\n CONTINUE: 100,\n SWITCHING_PROTOCOLS: 101,\n PROCESSING: 102,\n EARLY_HINTS: 103,\n RESPONSE_IS_STALE: 110, // Unofficial\n REVALIDATION_FAILED: 111, // Unofficial\n DISCONNECTED_OPERATION: 112, // Unofficial\n HEURISTIC_EXPIRATION: 113, // Unofficial\n MISCELLANEOUS_WARNING: 199, // Unofficial\n OK: 200,\n CREATED: 201,\n ACCEPTED: 202,\n NON_AUTHORITATIVE_INFORMATION: 203,\n NO_CONTENT: 204,\n RESET_CONTENT: 205,\n PARTIAL_CONTENT: 206,\n MULTI_STATUS: 207,\n ALREADY_REPORTED: 208,\n TRANSFORMATION_APPLIED: 214, // Unofficial\n IM_USED: 226,\n MISCELLANEOUS_PERSISTENT_WARNING: 299, // Unofficial\n MULTIPLE_CHOICES: 300,\n MOVED_PERMANENTLY: 301,\n FOUND: 302,\n SEE_OTHER: 303,\n NOT_MODIFIED: 304,\n USE_PROXY: 305,\n SWITCH_PROXY: 306, // No longer used\n TEMPORARY_REDIRECT: 307,\n PERMANENT_REDIRECT: 308,\n BAD_REQUEST: 400,\n UNAUTHORIZED: 401,\n PAYMENT_REQUIRED: 402,\n FORBIDDEN: 403,\n NOT_FOUND: 404,\n METHOD_NOT_ALLOWED: 405,\n NOT_ACCEPTABLE: 406,\n PROXY_AUTHENTICATION_REQUIRED: 407,\n REQUEST_TIMEOUT: 408,\n CONFLICT: 409,\n GONE: 410,\n LENGTH_REQUIRED: 411,\n PRECONDITION_FAILED: 412,\n PAYLOAD_TOO_LARGE: 413,\n URI_TOO_LONG: 414,\n UNSUPPORTED_MEDIA_TYPE: 415,\n RANGE_NOT_SATISFIABLE: 416,\n EXPECTATION_FAILED: 417,\n IM_A_TEAPOT: 418,\n PAGE_EXPIRED: 419, // Unofficial\n ENHANCE_YOUR_CALM: 420, // Unofficial\n MISDIRECTED_REQUEST: 421,\n UNPROCESSABLE_ENTITY: 422,\n LOCKED: 423,\n FAILED_DEPENDENCY: 424,\n TOO_EARLY: 425,\n UPGRADE_REQUIRED: 426,\n PRECONDITION_REQUIRED: 428,\n TOO_MANY_REQUESTS: 429,\n REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL: 430, // Unofficial\n REQUEST_HEADER_FIELDS_TOO_LARGE: 431,\n LOGIN_TIMEOUT: 440, // Unofficial\n NO_RESPONSE: 444, // Unofficial\n RETRY_WITH: 449, // Unofficial\n BLOCKED_BY_PARENTAL_CONTROL: 450, // Unofficial\n UNAVAILABLE_FOR_LEGAL_REASONS: 451,\n CLIENT_CLOSED_LOAD_BALANCED_REQUEST: 460, // Unofficial\n INVALID_X_FORWARDED_FOR: 463, // Unofficial\n REQUEST_HEADER_TOO_LARGE: 494, // Unofficial\n SSL_CERTIFICATE_ERROR: 495, // Unofficial\n SSL_CERTIFICATE_REQUIRED: 496, // Unofficial\n HTTP_REQUEST_SENT_TO_HTTPS_PORT: 497, // Unofficial\n INVALID_TOKEN: 498, // Unofficial\n CLIENT_CLOSED_REQUEST: 499, // Unofficial\n INTERNAL_SERVER_ERROR: 500,\n NOT_IMPLEMENTED: 501,\n BAD_GATEWAY: 502,\n SERVICE_UNAVAILABLE: 503,\n GATEWAY_TIMEOUT: 504,\n HTTP_VERSION_NOT_SUPPORTED: 505,\n VARIANT_ALSO_NEGOTIATES: 506,\n INSUFFICIENT_STORAGE: 507,\n LOOP_DETECTED: 508,\n BANDWIDTH_LIMIT_EXCEEDED: 509,\n NOT_EXTENDED: 510,\n NETWORK_AUTHENTICATION_REQUIRED: 511,\n WEB_SERVER_UNKNOWN_ERROR: 520, // Unofficial\n WEB_SERVER_IS_DOWN: 521, // Unofficial\n CONNECTION_TIMEOUT: 522, // Unofficial\n ORIGIN_IS_UNREACHABLE: 523, // Unofficial\n TIMEOUT_OCCURED: 524, // Unofficial\n SSL_HANDSHAKE_FAILED: 525, // Unofficial\n INVALID_SSL_CERTIFICATE: 526, // Unofficial\n RAILGUN_ERROR: 527, // Unofficial\n SITE_IS_OVERLOADED: 529, // Unofficial\n SITE_IS_FROZEN: 530, // Unofficial\n IDENTITY_PROVIDER_AUTHENTICATION_ERROR: 561, // Unofficial\n NETWORK_READ_TIMEOUT: 598, // Unofficial\n NETWORK_CONNECT_TIMEOUT: 599, // Unofficial\n};\nexports.FINISH = {\n SAFE: 0,\n SAFE_WITH_CB: 1,\n UNSAFE: 2,\n};\nexports.HEADER_STATE = {\n GENERAL: 0,\n CONNECTION: 1,\n CONTENT_LENGTH: 2,\n TRANSFER_ENCODING: 3,\n UPGRADE: 4,\n CONNECTION_KEEP_ALIVE: 5,\n CONNECTION_CLOSE: 6,\n CONNECTION_UPGRADE: 7,\n TRANSFER_ENCODING_CHUNKED: 8,\n};\nexports.METHODS_HTTP1_HEAD = {\n HEAD: 2,\n};\n/**\n * HTTP methods as defined by RFC-9110 and other specifications.\n * @see https://httpwg.org/specs/rfc9110.html#method.definitions\n */\nexports.METHODS_BASIC_HTTP = {\n DELETE: 0,\n GET: 1,\n ...exports.METHODS_HTTP1_HEAD,\n POST: 3,\n PUT: 4,\n CONNECT: 5,\n OPTIONS: 6,\n TRACE: 7,\n /**\n * @see https://www.rfc-editor.org/rfc/rfc5789.html\n */\n PATCH: 28,\n /* RFC-2068, section 19.6.1.2 */\n LINK: 31,\n UNLINK: 32,\n};\nexports.METHODS_WEBDAV = {\n COPY: 8,\n LOCK: 9,\n MKCOL: 10,\n MOVE: 11,\n PROPFIND: 12,\n PROPPATCH: 13,\n SEARCH: 14,\n UNLOCK: 15,\n BIND: 16,\n REBIND: 17,\n UNBIND: 18,\n ACL: 19,\n};\nexports.METHODS_SUBVERSION = {\n REPORT: 20,\n MKACTIVITY: 21,\n CHECKOUT: 22,\n MERGE: 23,\n};\nexports.METHODS_UPNP = {\n 'M-SEARCH': 24,\n NOTIFY: 25,\n SUBSCRIBE: 26,\n UNSUBSCRIBE: 27,\n};\nexports.METHODS_CALDAV = {\n MKCALENDAR: 30,\n};\nexports.METHODS_NON_STANDARD = {\n /**\n * Not defined in any RFC but commonly used\n */\n PURGE: 29,\n /* DRAFT https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-method-w-body-02.html */\n QUERY: 46,\n};\nexports.METHODS_ICECAST = {\n SOURCE: 33,\n};\nexports.METHODS_AIRPLAY = {\n GET: 1,\n POST: 3,\n};\nexports.METHODS_RAOP = {\n FLUSH: 45,\n};\n/* RFC-2326 RTSP */\nexports.METHODS_RTSP = {\n OPTIONS: exports.METHODS_BASIC_HTTP.OPTIONS,\n DESCRIBE: 35,\n ANNOUNCE: 36,\n SETUP: 37,\n PLAY: 38,\n PAUSE: 39,\n TEARDOWN: 40,\n GET_PARAMETER: 41,\n SET_PARAMETER: 42,\n REDIRECT: 43,\n RECORD: 44,\n ...exports.METHODS_AIRPLAY,\n ...exports.METHODS_RAOP,\n};\nexports.METHODS_HTTP1 = {\n ...exports.METHODS_BASIC_HTTP,\n ...exports.METHODS_WEBDAV,\n ...exports.METHODS_SUBVERSION,\n ...exports.METHODS_UPNP,\n ...exports.METHODS_CALDAV,\n ...exports.METHODS_NON_STANDARD,\n // TODO(indutny): should we allow it with HTTP?\n ...exports.METHODS_ICECAST,\n};\nexports.METHODS_HTTP2 = {\n /**\n * RFC-9113, section 11.6\n * @see https://www.rfc-editor.org/rfc/rfc9113.html#preface\n */\n PRI: 34,\n};\nexports.METHODS_HTTP = {\n ...exports.METHODS_HTTP1,\n ...exports.METHODS_HTTP2,\n};\nexports.METHODS = {\n ...exports.METHODS_HTTP1,\n ...exports.METHODS_HTTP2,\n ...exports.METHODS_RTSP,\n};\n// ALPHA: https://tools.ietf.org/html/rfc5234#appendix-B.1\nexports.ALPHA = [\n \"A\", \"a\", \"B\", \"b\", \"C\", \"c\", \"D\", \"d\",\n \"E\", \"e\", \"F\", \"f\", \"G\", \"g\", \"H\", \"h\",\n \"I\", \"i\", \"J\", \"j\", \"K\", \"k\", \"L\", \"l\",\n \"M\", \"m\", \"N\", \"n\", \"O\", \"o\", \"P\", \"p\",\n \"Q\", \"q\", \"R\", \"r\", \"S\", \"s\", \"T\", \"t\",\n \"U\", \"u\", \"V\", \"v\", \"W\", \"w\", \"X\", \"x\",\n \"Y\", \"y\", \"Z\", \"z\",\n];\nexports.NUM_MAP = {\n 0: 0, 1: 1, 2: 2, 3: 3, 4: 4,\n 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,\n};\nexports.HEX_MAP = {\n 0: 0, 1: 1, 2: 2, 3: 3, 4: 4,\n 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,\n A: 0XA, B: 0XB, C: 0XC, D: 0XD, E: 0XE, F: 0XF,\n a: 0xa, b: 0xb, c: 0xc, d: 0xd, e: 0xe, f: 0xf,\n};\n// DIGIT: https://tools.ietf.org/html/rfc5234#appendix-B.1\nexports.DIGIT = [\n '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n];\nexports.ALPHANUM = [...exports.ALPHA, ...exports.DIGIT];\nexports.MARK = ['-', '_', '.', '!', '~', '*', '\\'', '(', ')'];\nexports.USERINFO_CHARS = [...exports.ALPHANUM, ...exports.MARK, '%', ';', ':', '&', '=', '+', '$', ','];\n// TODO(indutny): use RFC\nexports.URL_CHAR = [\n '!', '\"', '$', '%', '&', '\\'',\n '(', ')', '*', '+', ',', '-', '.', '/',\n ':', ';', '<', '=', '>',\n '@', '[', '\\\\', ']', '^', '_',\n '`',\n '{', '|', '}', '~',\n ...exports.ALPHANUM\n];\nexports.HEX = [...exports.DIGIT, 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'];\n/* Tokens as defined by rfc 2616. Also lowercases them.\n * token = 1*<any CHAR except CTLs or separators>\n * separators = \"(\" | \")\" | \"<\" | \">\" | \"@\"\n * | \",\" | \";\" | \":\" | \"\\\" | <\">\n * | \"/\" | \"[\" | \"]\" | \"?\" | \"=\"\n * | \"{\" | \"}\" | SP | HT\n */\nexports.TOKEN = [\n '!', '#', '$', '%', '&', '\\'',\n '*', '+', '-', '.',\n '^', '_', '`',\n '|', '~',\n ...exports.ALPHANUM\n];\n// HTAB: https://tools.ietf.org/html/rfc5234#appendix-B.1\nexports.HTAB = ['\\t'];\n// SP: https://tools.ietf.org/html/rfc5234#appendix-B.1\nexports.SP = [' '];\n// VCHAR: https://tools.ietf.org/html/rfc5234#appendix-B.1\nconst VCHAR = [\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,\n 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,\n 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,\n 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,\n 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,\n 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,\n 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60,\n 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,\n 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,\n 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,\n 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e,\n];\n// OBS_TEXT: https://datatracker.ietf.org/doc/html/rfc9110#name-collected-abnf\n// 0x80 - 0xff\nconst OBS_TEXT = [\n 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n];\nexports.HTAB_SP_VCHAR_OBS_TEXT = [...exports.HTAB, ...exports.SP, ...VCHAR, ...OBS_TEXT];\nexports.HEADER_CHARS = exports.HTAB_SP_VCHAR_OBS_TEXT;\nconst RELAXED_CTRL_CHARS = [\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Before TAB\n 0x0b, 0x0c, // VT, FF (between TAB and CR)\n 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, // After CR/LF, before space\n 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,\n 0x1e, 0x1f,\n 0x7f, // DEL\n];\n// Relaxed header chars includes control characters (above) that are not allowed\n// by default. This excludes only NULL (0x00), CR (0x0d), LF (0x0a).\nexports.RELAXED_HEADER_CHARS = [...RELAXED_CTRL_CHARS, ...exports.HEADER_CHARS];\n// ',' = \\x2c\nexports.CONNECTION_TOKEN_CHARS = [\n ...exports.HTAB, ...exports.SP,\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,\n 0x29, 0x2a, 0x2b, /* */ 0x2d, 0x2e, 0x2f, 0x30,\n 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,\n 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,\n 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,\n 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,\n 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60,\n 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,\n 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,\n 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,\n 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e,\n ...OBS_TEXT\n];\n// QDTEXT: https://datatracker.ietf.org/doc/html/rfc9110#section-5.6.4\nexports.QDTEXT = [\n ...exports.HTAB, ...exports.SP,\n 0x21,\n 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,\n 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32,\n 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,\n 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42,\n 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,\n 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,\n 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a,\n 0x5b,\n 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64,\n 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,\n 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74,\n 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c,\n 0x7d, 0x7e,\n ...OBS_TEXT\n];\nexports.MAJOR = exports.NUM_MAP;\nexports.MINOR = exports.MAJOR;\nexports.SPECIAL_HEADERS = {\n 'connection': exports.HEADER_STATE.CONNECTION,\n 'content-length': exports.HEADER_STATE.CONTENT_LENGTH,\n 'proxy-connection': exports.HEADER_STATE.CONNECTION,\n 'transfer-encoding': exports.HEADER_STATE.TRANSFER_ENCODING,\n 'upgrade': exports.HEADER_STATE.UPGRADE,\n};\nexports.default = {\n ERROR: exports.ERROR,\n TYPE: exports.TYPE,\n FLAGS: exports.FLAGS,\n LENIENT_FLAGS: exports.LENIENT_FLAGS,\n STATUSES: exports.STATUSES,\n FINISH: exports.FINISH,\n HEADER_STATE: exports.HEADER_STATE,\n ALPHA: exports.ALPHA,\n NUM_MAP: exports.NUM_MAP,\n HEX_MAP: exports.HEX_MAP,\n DIGIT: exports.DIGIT,\n ALPHANUM: exports.ALPHANUM,\n MARK: exports.MARK,\n USERINFO_CHARS: exports.USERINFO_CHARS,\n URL_CHAR: exports.URL_CHAR,\n HEX: exports.HEX,\n TOKEN: exports.TOKEN,\n HEADER_CHARS: exports.HEADER_CHARS,\n RELAXED_HEADER_CHARS: exports.RELAXED_HEADER_CHARS,\n CONNECTION_TOKEN_CHARS: exports.CONNECTION_TOKEN_CHARS,\n QDTEXT: exports.QDTEXT,\n HTAB_SP_VCHAR_OBS_TEXT: exports.HTAB_SP_VCHAR_OBS_TEXT,\n MAJOR: exports.MAJOR,\n MINOR: exports.MINOR,\n SPECIAL_HEADERS: exports.SPECIAL_HEADERS,\n METHODS: exports.METHODS,\n METHODS_HTTP: exports.METHODS_HTTP,\n METHODS_HTTP1_HEAD: exports.METHODS_HTTP1_HEAD,\n METHODS_HTTP1: exports.METHODS_HTTP1,\n METHODS_HTTP2: exports.METHODS_HTTP2,\n METHODS_ICECAST: exports.METHODS_ICECAST,\n METHODS_RTSP: exports.METHODS_RTSP,\n};","import fs from 'node:fs'\nimport * as constants from './llhttp/constants.cjs'\n\nexport { constants }\n\nexport interface RequestHeadersComplete {\n versionMajor: number\n versionMinor: number\n rawHeaders: Array<string>\n method: string\n url: string\n upgrade: boolean\n shouldKeepAlive: boolean\n}\n\nexport interface ResponseHeadersComplete {\n versionMajor: number\n versionMinor: number\n rawHeaders: Array<string>\n statusCode: number\n statusMessage: string\n upgrade: boolean\n shouldKeepAlive: boolean\n}\n\nconst KIND_REQUEST = constants.TYPE.REQUEST\nconst KIND_RESPONSE = constants.TYPE.RESPONSE\n\ntype ParserKind = typeof KIND_REQUEST | typeof KIND_RESPONSE\n\nexport interface ParserCallbacks<K extends ParserKind> {\n onError?: (error: Error) => void\n onMessageBegin?: () => number | void\n onHeadersComplete?: (\n info: K extends typeof KIND_REQUEST\n ? RequestHeadersComplete\n : ResponseHeadersComplete\n ) => number | void\n onBody?: (body: Buffer) => number | void\n onMessageComplete?: () => number | void\n}\n\nexport type RequestParserCallbacks = ParserCallbacks<typeof KIND_REQUEST>\nexport type ResponseParserCallbacks = ParserCallbacks<typeof KIND_RESPONSE>\n\nconst kPointer = Symbol('kPtr')\nconst kUrl = Symbol('kUrl')\nconst kStatusMessage = Symbol('kStatusMessage')\nconst kHeadersFields = Symbol('kHeadersFields')\nconst kHeadersValues = Symbol('kHeadersValues')\nconst kLastHeaderCallback = Symbol('kLastHeaderCallback')\nconst kCallbacks = Symbol('kCallbacks')\nconst kType = Symbol('kType')\n\nconst HEADER_CB_NONE = 0\nconst HEADER_CB_FIELD = 1\nconst HEADER_CB_VALUE = 2\n\nconst parsersMap = new Map<number, HttpParser<any>>()\n\nconst methodNames = Object.fromEntries(\n Object.entries(constants.METHODS).map(([name, num]) => [num, name])\n) as Record<number, string>\n\nfunction readStringFrom(pointer: number, length: number): string {\n return Buffer.from(llhttp_memory.buffer, pointer, length).toString('latin1')\n}\n\n/**\n * @note Reference the base URL through a variable. Bundlers (e.g. Vite)\n * statically rewrite the `new URL('...', import.meta.url)` pattern into\n * an asset URL resolved against the served origin, which breaks reading\n * the WASM binary from the file system in DOM-like test environments.\n */\nconst wasmBaseUrl = import.meta.url\n\nconst llhttpModule = new WebAssembly.Module(\n fs.readFileSync(new URL('./llhttp/llhttp.wasm', wasmBaseUrl))\n)\n\nconst llhttpInstance = new WebAssembly.Instance(llhttpModule, {\n env: {\n wasm_on_message_begin(parserPointer: number) {\n const parser = parsersMap.get(parserPointer)!\n parser[kUrl] = ''\n parser[kStatusMessage] = ''\n parser[kHeadersFields] = []\n parser[kHeadersValues] = []\n parser[kLastHeaderCallback] = HEADER_CB_NONE\n return parser[kCallbacks].onMessageBegin?.() ?? 0\n },\n // Request only\n wasm_on_url(parserPointer: number, at: number, length: number) {\n parsersMap.get(parserPointer)![kUrl] = readStringFrom(at, length)\n return 0\n },\n // Response only\n wasm_on_status(parserPointer: number, at: number, length: number) {\n parsersMap.get(parserPointer)![kStatusMessage] = readStringFrom(\n at,\n length\n )\n return 0\n },\n wasm_on_header_field(parserPointer: number, at: number, length: number) {\n const parser = parsersMap.get(parserPointer)!\n const chunk = readStringFrom(at, length)\n const fields = parser[kHeadersFields]\n\n // llhttp emits header field/value across multiple callbacks when the\n // bytes span buffer boundaries. Concatenate consecutive same-type\n // callbacks into a single entry; switch entries on field<->value transitions.\n if (parser[kLastHeaderCallback] === HEADER_CB_FIELD) {\n fields[fields.length - 1] += chunk\n } else {\n fields.push(chunk)\n parser[kLastHeaderCallback] = HEADER_CB_FIELD\n }\n return 0\n },\n wasm_on_header_value(parserPointer: number, at: number, length: number) {\n const parser = parsersMap.get(parserPointer)!\n const chunk = readStringFrom(at, length)\n const values = parser[kHeadersValues]\n\n if (parser[kLastHeaderCallback] === HEADER_CB_VALUE) {\n values[values.length - 1] += chunk\n } else {\n values.push(chunk)\n parser[kLastHeaderCallback] = HEADER_CB_VALUE\n }\n return 0\n },\n wasm_on_headers_complete(\n parserPointer: number,\n statusCode: number,\n rawUpgrade: number,\n rawShouldKeepAlive: number\n ) {\n const parser = parsersMap.get(parserPointer)!\n const versionMajor = llhttp_get_version_major(parserPointer)\n const versionMinor = llhttp_get_version_minor(parserPointer)\n const rawHeaders: Array<string> = []\n const upgrade = rawUpgrade === 1\n const shouldKeepAlive = rawShouldKeepAlive === 1\n\n for (let c = 0; c < parser[kHeadersFields].length; c++) {\n rawHeaders.push(parser[kHeadersFields][c]!, parser[kHeadersValues][c]!)\n }\n\n if (parser[kType] === KIND_REQUEST) {\n const method = methodNames[llhttp_get_method(parserPointer)]\n const url = parser[kUrl]\n const callback = parser[kCallbacks] as ParserCallbacks<\n typeof KIND_REQUEST\n >\n\n return (\n callback.onHeadersComplete?.({\n versionMajor,\n versionMinor,\n rawHeaders,\n method,\n url,\n upgrade,\n shouldKeepAlive,\n }) ?? 0\n )\n } else {\n const statusCode = llhttp_get_status_code(parserPointer) as number\n const statusMessage = parser[kStatusMessage]\n const callback = parser[kCallbacks] as ParserCallbacks<\n typeof KIND_RESPONSE\n >\n\n return (\n callback.onHeadersComplete?.({\n versionMajor,\n versionMinor,\n rawHeaders,\n statusCode,\n statusMessage,\n upgrade,\n shouldKeepAlive,\n }) ?? 0\n )\n }\n },\n wasm_on_body(parserPointer: number, at: number, length: number) {\n const parser = parsersMap.get(parserPointer)!\n // Create a copy of the body chunk, as the underlying memory buffer is reused by llhttp and can be overwritten on the next callback call.\n // Maybe not the most efficient way, but it is simple and safe.\n const body = Buffer.from(new Uint8Array(llhttp_memory.buffer, at, length))\n return parser[kCallbacks].onBody?.(body) ?? 0\n },\n wasm_on_message_complete(parserPointer: number) {\n return (\n parsersMap.get(parserPointer)![kCallbacks].onMessageComplete?.() ?? 0\n )\n },\n },\n})\n\nconst llhttp_memory = llhttpInstance.exports.memory as WebAssembly.Memory\nconst llhttp_alloc = llhttpInstance.exports.llhttp_alloc as CallableFunction\nconst llhttp_malloc = llhttpInstance.exports.malloc as CallableFunction\nconst llhttp_execute = llhttpInstance.exports.llhttp_execute as CallableFunction\nconst llhttp_get_type = llhttpInstance.exports\n .llhttp_get_type as CallableFunction\nconst llhttp_get_upgrade = llhttpInstance.exports\n .llhttp_get_upgrade as CallableFunction\nconst llhttp_should_keep_alive = llhttpInstance.exports\n .llhttp_should_keep_alive as CallableFunction\nconst llhttp_get_method = llhttpInstance.exports\n .llhttp_get_method as CallableFunction\nconst llhttp_get_status_code = llhttpInstance.exports\n .llhttp_get_status_code as CallableFunction\nconst llhttp_get_version_minor = llhttpInstance.exports\n .llhttp_get_http_minor as CallableFunction\nconst llhttp_get_version_major = llhttpInstance.exports\n .llhttp_get_http_major as CallableFunction\nconst llhttp_get_error_reason = llhttpInstance.exports\n .llhttp_get_error_reason as CallableFunction\nconst llhttp_get_error_pos = llhttpInstance.exports\n .llhttp_get_error_pos as CallableFunction\nconst llhttp_free = llhttpInstance.exports.free as CallableFunction\n\nconst initialize = llhttpInstance.exports._initialize as CallableFunction\ninitialize() // wasi reactor\n\nexport class HttpParser<K extends ParserKind> {\n [kPointer]: number;\n [kUrl]: string = '';\n [kStatusMessage]: string = '';\n [kHeadersFields]: Array<string> = [];\n [kHeadersValues]: Array<string> = [];\n [kLastHeaderCallback]: number = HEADER_CB_NONE;\n [kCallbacks]: ParserCallbacks<K>;\n [kType]: ParserKind\n\n constructor(type: K, callbacks: ParserCallbacks<K>) {\n this[kType] = type\n this[kCallbacks] = callbacks\n\n const parserPointer = llhttp_alloc(type)\n\n if (parserPointer === 0) {\n throw new Error('Failed to allocate llhttp parser')\n }\n\n this[kPointer] = parserPointer\n parsersMap.set(this[kPointer], this)\n }\n\n destroy() {\n // Guard against multiple calls to free/destroy.\n if (this[kPointer] === 0) {\n return\n }\n\n parsersMap.delete(this[kPointer])\n llhttp_free(this[kPointer])\n this[kPointer] = 0\n }\n\n execute(data: Buffer) {\n const pointer = llhttp_malloc(data.byteLength)\n\n if (pointer === 0) {\n throw new Error('Failed to allocate llhttp input buffer')\n }\n\n let ret: number\n try {\n const buffer = new Uint8Array(llhttp_memory.buffer)\n buffer.set(data, pointer)\n ret = llhttp_execute(this[kPointer], pointer, data.byteLength)\n } catch (error) {\n // Free the input buffer if a user callback threw synchronously,\n // otherwise the wasm heap leaks the chunk on every execute() call.\n llhttp_free(pointer)\n throw error\n }\n\n if (ret === constants.ERROR.PAUSED_UPGRADE) {\n // Find how many bytes llhttp consumed\n const errorPos = llhttp_get_error_pos(this[kPointer])\n const consumed = errorPos - pointer\n llhttp_free(pointer)\n // Return the unconsumed trailing bytes (tunnel/protocol data)\n return data.subarray(consumed)\n }\n\n llhttp_free(pointer)\n this.#checkError(ret)\n\n return null // fully consumed\n }\n\n #checkError(errorCode: number) {\n if (errorCode === constants.ERROR.OK) {\n return\n }\n\n const errorPointer = llhttp_get_error_reason(this[kPointer])\n const buffer = new Uint8Array(llhttp_memory.buffer)\n const length = buffer.indexOf(0, errorPointer) - errorPointer\n\n const error = new Error(readStringFrom(errorPointer, length))\n\n if (this[kCallbacks].onError) {\n this[kCallbacks].onError(error)\n return\n }\n\n throw error\n }\n}\n","import { Readable } from 'node:stream'\nimport { invariant } from 'outvariant'\nimport { FetchRequest, FetchResponse } from '../../utils/fetch-utils'\nimport { HttpParser } from './http-parser/index'\n\ninterface HttpRequestParserOptions {\n onError: (error: Error) => void\n connectionOptions: {\n method?: string\n url: URL\n }\n onRequest: (request: Request, abortController: AbortController) => void\n onMessageComplete?: () => void\n}\n\nexport class HttpRequestParser extends HttpParser<1> {\n #requestBodyStream?: Readable\n #upgrade = false\n\n constructor(options: HttpRequestParserOptions) {\n super(1, {\n onError: options.onError,\n onHeadersComplete: ({ rawHeaders, method, url: path, upgrade }) => {\n this.#upgrade = upgrade\n /**\n * @note When the socket is reused, \"connectionOptions\" will point\n * to the \"net.connect()\" call options that established the connection,\n * which may differ from the description of the current request (e.g. method).\n * Rely on the HTTPParser supplying us with the correct \"rawMethod\" number.\n */\n const finalMethod = (\n method ||\n options.connectionOptions.method ||\n 'GET'\n ).toUpperCase()\n\n const url = new URL(path || '', options.connectionOptions.url)\n const headers = FetchResponse.parseRawHeaders([...rawHeaders])\n\n // Translate the basic authorization to request headers.\n // Constructing a Request instance with a URL containing auth is no-op.\n if (url.username || url.password) {\n if (!headers.has('authorization')) {\n const credentials = Buffer.from(\n `${url.username}:${url.password}`\n ).toString('base64')\n headers.set('authorization', `Basic ${credentials}`)\n }\n url.username = ''\n url.password = ''\n }\n\n this.#requestBodyStream = new Readable({\n /**\n * @note Provide the `read()` method so a `Readable` could be\n * used as the actual request body (the stream calls \"read()\").\n */\n read: () => {},\n })\n\n /**\n * @note Expose an abort controller for the parsed request so the\n * consumer can abort it (e.g. when the client destroys the\n * connection before the request is handled).\n */\n const abortController = new AbortController()\n\n const request = new FetchRequest(url, {\n method: finalMethod,\n headers,\n credentials: 'same-origin',\n body: Readable.toWeb(this.#requestBodyStream) as any,\n signal: abortController.signal,\n })\n options.onRequest(request, abortController)\n },\n onBody: (chunk) => {\n invariant(\n this.#requestBodyStream,\n 'Failed to write to a request stream: stream does not exist. This is likely an issue with the library. Please report it on GitHub.'\n )\n\n this.#requestBodyStream.push(chunk)\n },\n onMessageComplete: () => {\n this.#requestBodyStream?.push(null)\n this.#requestBodyStream = undefined\n\n /**\n * @note An upgraded exchange (e.g. \"CONNECT\", WebSocket) has\n * no message boundary: it takes the connection over, and the\n * bytes that follow belong to it, not to a next exchange.\n */\n if (!this.#upgrade) {\n options.onMessageComplete?.()\n }\n },\n })\n }\n\n public free(error?: Error): void {\n this.destroy()\n this.#requestBodyStream?.destroy(error)\n this.#requestBodyStream = undefined\n }\n}\n\nexport class HttpResponseParser extends HttpParser<2> {\n #responseBodyStream?: Readable | null\n #status = 0\n\n constructor(options: {\n onResponse: (response: Response) => void\n onError: (error: Error) => void\n onMessageComplete?: (status: number) => void\n }) {\n super(2, {\n onError: options.onError,\n onHeadersComplete: ({\n rawHeaders,\n statusCode: status,\n statusMessage: statusText,\n }) => {\n this.#status = status\n const headers = FetchResponse.parseRawHeaders([...rawHeaders])\n\n const response = new FetchResponse(\n FetchResponse.isResponseWithBody(status)\n ? (Readable.toWeb(\n (this.#responseBodyStream = new Readable({ read() {} }))\n ) as any)\n : null,\n {\n status,\n statusText,\n headers,\n }\n )\n\n options.onResponse(response)\n },\n onBody: (chunk) => {\n invariant(\n this.#responseBodyStream,\n 'Failed to read from a response stream: stream does not exist. This is likely an issue with the library. Please report it on GitHub.'\n )\n\n this.#responseBodyStream.push(chunk)\n },\n onMessageComplete: () => {\n this.#responseBodyStream?.push(null)\n this.#responseBodyStream = null\n options.onMessageComplete?.(this.#status)\n },\n })\n }\n\n public free(error?: Error): void {\n this.destroy()\n\n if (error) {\n this.#responseBodyStream?.destroy(error)\n }\n\n this.#responseBodyStream = null\n }\n}\n","export function isNodeLikeError(\n error: unknown\n): error is NodeJS.ErrnoException {\n if (error == null) {\n return false\n }\n\n if (!(error instanceof Error)) {\n return false\n }\n\n return 'code' in error && 'errno' in error\n}\n","import type { Emitter } from 'rettime'\nimport { until } from '@open-draft/until'\nimport {\n HttpRequestEvent,\n HttpRequestEventData,\n UnhandledHttpException,\n type HttpRequestEventMap,\n} from '../events/http'\nimport { RequestController } from '../request-controller'\nimport {\n createServerErrorResponse,\n isResponseError,\n isResponseLike,\n} from './response-utils'\nimport { InterceptorError } from '../interceptor-error'\nimport { isNodeLikeError } from './is-node-like-error'\nimport { isObject } from './is-object'\nimport { formatRequest, type Logger } from './logger'\n\nexport interface HandleRequestOptions {\n initiator: unknown\n requestId: string\n request: Request\n emitter: Emitter<HttpRequestEventMap>\n controller: RequestController\n logger?: Logger\n}\n\nexport async function handleRequest(\n options: HandleRequestOptions\n): Promise<void> {\n if (options.logger?.isEnabled('default')) {\n void formatRequest(options.request).then((message) => {\n options.logger?.info('[%s] %s', options.requestId, message)\n })\n }\n\n const handleResponse = async (\n response: Response | Error | Record<string, any>\n ) => {\n if (response instanceof Error) {\n await options.controller.errorWith(response)\n return true\n }\n\n // Handle \"Response.error()\" instances.\n if (isResponseError(response)) {\n await options.controller.respondWith(response)\n return true\n }\n\n /**\n * Handle normal responses or response-like objects.\n * @note This must come before the arbitrary object check\n * since Response instances are, in fact, objects.\n */\n if (isResponseLike(response)) {\n await options.controller.respondWith(response)\n return true\n }\n\n // Handle arbitrary objects provided to `.errorWith(reason)`.\n if (isObject(response)) {\n await options.controller.errorWith(response)\n return true\n }\n\n return false\n }\n\n const handleResponseError = async (error: unknown): Promise<boolean> => {\n // Forward the special interceptor error instances\n // to the developer. These must not be handled in any way.\n if (error instanceof InterceptorError) {\n throw resultError\n }\n\n // Support mocking Node.js-like errors.\n if (isNodeLikeError(error)) {\n await options.controller.errorWith(error)\n return true\n }\n\n // Handle thrown responses.\n if (error instanceof Response) {\n return await handleResponse(error)\n }\n\n return false\n }\n\n const requestAbortPromise = Promise.withResolvers<void>()\n let requestAbortReason: unknown\n let isRequestAborted = false\n const onAbort = () => {\n isRequestAborted = true\n requestAbortReason = options.request.signal?.reason\n requestAbortPromise.reject(requestAbortReason)\n }\n\n /**\n * @note `signal` is not always defined in React Native.\n */\n if (options.request.signal) {\n if (options.request.signal.aborted) {\n await options.controller.errorWith(options.request.signal.reason)\n return\n }\n\n options.request.signal.addEventListener('abort', onAbort, { once: true })\n }\n\n const [resultError] = await until(async () => {\n // Emit the \"request\" event and wait until all the listeners\n // for that event are finished (e.g. async listeners awaited).\n // By the end of this promise, the developer cannot affect the\n // request anymore.\n const requestEventData: HttpRequestEventData = {\n initiator: options.initiator,\n requestId: options.requestId,\n request: options.request,\n controller: options.controller,\n }\n const requestEvent = new HttpRequestEvent(requestEventData)\n const requestListenersPromise = options.emitter.emitAsPromise(requestEvent)\n\n await Promise.race([\n // Short-circuit the request handling promise if the request gets aborted.\n requestAbortPromise.promise,\n requestListenersPromise,\n options.controller.handled,\n ])\n\n /**\n * @note If the \"request\" listener has replaced the request instance,\n * propagate that mutation back to the underlying insterceptor.\n * This happens with XMLHttpRequest that replaces request instances\n * to correctly reflect the \"withCredentials\" option on the Fetch API request.\n */\n if (requestEvent.request !== options.request) {\n options.request = requestEvent.request\n }\n })\n\n options.request.signal?.removeEventListener('abort', onAbort)\n\n // Handle the request being aborted while waiting for the request listeners.\n if (isRequestAborted) {\n await options.controller.errorWith(requestAbortReason)\n return\n }\n\n if (resultError) {\n // Handle the error during the request listener execution.\n // These can be thrown responses or request errors.\n if (await handleResponseError(resultError)) {\n return\n }\n\n // If the developer has added \"unhandledException\" listeners,\n // allow them to handle the error. They can translate it to a\n // mocked response, network error, or forward it as-is.\n if (options.emitter.listenerCount('unhandledException') > 0) {\n // Create a new request controller just for the unhandled exception case.\n // This is needed because the original controller might have been already\n // interacted with (e.g. \"respondWith\" or \"errorWith\" called on it).\n const unhandledExceptionController = new RequestController(\n options.request,\n {\n /**\n * @note Intentionally empty passthrough handle.\n * This controller is created within another controller and we only need\n * to know if `unhandledException` listeners handled the request.\n */\n passthrough() {},\n async respondWith(response) {\n await handleResponse(response)\n },\n async errorWith(reason) {\n /**\n * @note Handle the result of the unhandled controller\n * in the same way as the original request controller.\n * The exception here is that thrown errors within the\n * \"unhandledException\" event do NOT result in another\n * emit of the same event. They are forwarded as-is.\n */\n await options.controller.errorWith(reason)\n },\n }\n )\n\n await options.emitter.emitAsPromise(\n new UnhandledHttpException({\n initiator: options.initiator,\n error: resultError,\n request: options.request,\n requestId: options.requestId,\n controller: unhandledExceptionController,\n })\n )\n\n // If all the \"unhandledException\" listeners have finished\n // but have not handled the request in any way, passthrough.\n if (\n unhandledExceptionController.readyState !== RequestController.PENDING\n ) {\n return\n }\n }\n\n // Otherwise, coerce unhandled exceptions to a 500 Internal Server Error response.\n await options.controller.respondWith(\n createServerErrorResponse(resultError)\n )\n return\n }\n\n // If the request hasn't been handled by this point, passthrough.\n if (options.controller.readyState === RequestController.PENDING) {\n return await options.controller.passthrough()\n }\n\n return options.controller.handled\n}\n","import net from 'node:net'\nimport {\n METHODS,\n STATUS_CODES,\n ServerResponse,\n IncomingMessage,\n} from 'node:http'\nimport { invariant } from 'outvariant'\nimport { HttpResponseEvent, type HttpRequestEventMap } from '../../events/http'\nimport { RequestController } from '../../request-controller'\nimport {\n getRawFetchHeaders,\n recordRawFetchHeaders,\n} from '../ClientRequest/utils/record-raw-headers'\nimport { SocketInterceptor } from '../net'\nimport { connectionOptionsToUrl } from '../net/utils/connection-options-to-url'\nimport { toBuffer } from '../../utils/buffer-utils'\nimport { createRequestId } from '../../create-request-id'\nimport { HttpRequestParser, HttpResponseParser } from './http-parser'\nimport { handleRequest, HandleRequestOptions } from '../../utils/handle-request'\nimport { isResponseError, kErrorResponse } from '../../utils/response-utils'\nimport { createLogger } from '../../utils/logger'\nimport {\n kRawSocket,\n SocketController,\n type FlushPendingDataFunction,\n} from '../net/socket-controller'\nimport { unwrapPendingData } from '../net/utils/flush-writes'\nimport { FetchResponse } from '../../utils/fetch-utils'\nimport { requestContext } from '../../request-context'\nimport { Interceptor } from '#/src/interceptor'\n\nconst httpLogger = createLogger('http-request')\n\n/**\n * Interceptor for HTTP requests in Node.js.\n * Routes socket connections through an HTTP parser.\n */\nexport class NodeHttpRequestSource extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol.for('node-http-request-source')\n\n protected predicate(): boolean {\n return true\n }\n\n protected setup(): void {\n const socketInterceptor = Interceptor.singleton(SocketInterceptor)\n socketInterceptor.apply(this)\n this.subscriptions.push(() => {\n socketInterceptor.dispose(this)\n })\n\n /**\n * @note Record the raw values provided to Headers set/append\n * in order to support \"IncomingMessage.prototype.rawHeaders\".\n * This is meant for the headers in mocked responses.\n */\n this.subscriptions.push(recordRawFetchHeaders())\n\n const controller = new AbortController()\n this.subscriptions.push(() => controller.abort())\n\n socketInterceptor.on(\n 'connection',\n ({ connectionOptions, socket, controller: socketController }) => {\n let isHttpConnection: boolean | undefined\n let requestParser: HttpRequestParser | undefined\n let tunnelUrl: URL | undefined\n let abortPendingRequest: (() => void) | undefined\n let pendingRequestController: RequestController | undefined\n\n // A malformed request loses the boundary for subsequent requests.\n // Preserve the original bytes for the client and server to handle.\n const stopParsingRequests = (error: Error) => {\n httpLogger.verbose('stopping HTTP request parsing: %o', error)\n isHttpConnection = false\n\n if (\n pendingRequestController?.readyState === RequestController.PENDING\n ) {\n void pendingRequestController.passthrough()\n } else {\n socketController.decline()\n }\n\n requestParser?.free(error)\n }\n\n /**\n * @note Capture the request context of the connection itself.\n * The socket is created synchronously within the request async\n * context (e.g. inside the patched `http.request()`), but the\n * first data may reach the socket from a foreign context (e.g.\n * a form-data stream piped into the request), where sampling\n * the request context yields nothing.\n */\n const connectionRequestContext = requestContext.getStore()\n\n /**\n * @note The client destroys the socket synchronously (e.g. Undici\n * on request abort) but the socket teardown events (\"error\",\n * \"close\") are emitted asynchronously, after the consumer has\n * already observed the rejected request promise. Hook into the\n * destroy itself so the pending request is aborted before any\n * of its listeners can resume.\n */\n const rawSocket = socketController[kRawSocket]\n const realSocketDestroy = rawSocket._destroy.bind(rawSocket)\n rawSocket._destroy = (error, callback) => {\n abortPendingRequest?.()\n realSocketDestroy(error, callback)\n }\n\n /**\n * @note Only inspect the first sent packet to determine the protocol.\n * A single socket cannot be used for different protocols.\n */\n socket.on('data', (chunk) => {\n if (isHttpConnection === false) {\n socketController.decline()\n return\n }\n\n /**\n * @note A mocked \"CONNECT\" request has established a tunnel.\n * The data that follows belongs to a new exchange addressed to\n * the tunnel target. The parser stopped at the tunnel boundary\n * (HTTP upgrade semantics), so tear it down and detect the\n * tunneled protocol anew, like on a fresh connection.\n */\n if (tunnelUrl && requestParser) {\n requestParser.free()\n requestParser = undefined\n isHttpConnection = undefined\n\n /**\n * @note Retarget the connection to the tunnel authority.\n * The exchanges that follow belong to the tunnel target,\n * so an unclaimed exchange (HTTP or not) must pass through\n * to that target — not to the proxy, which never actually\n * established this tunnel — like a real established tunnel\n * relays its traffic.\n */\n socketController.reset({\n host: tunnelUrl.hostname,\n port: Number(tunnelUrl.port) || 80,\n path: null,\n })\n }\n\n if (requestParser) {\n requestParser.execute(toBuffer(chunk))\n return\n }\n\n const httpMessage = chunk.toString()\n const httpMethod = httpMessage.split(' ')[0] || ''\n\n // Decline non-HTTP connections so the socket controller can\n // pass them through once every subscriber has declined.\n if (!METHODS.includes(httpMethod.toUpperCase())) {\n isHttpConnection = false\n socketController.decline()\n return\n }\n\n isHttpConnection = true\n\n const baseUrl =\n tunnelUrl ?? connectionOptionsToUrl(connectionOptions, socket)\n\n httpLogger.verbose('handling http message %o', {\n httpMessage,\n httpMethod,\n baseUrl,\n })\n\n // Get the request initiator from the async context, falling\n // back to the context captured at the connection time, then\n // to the underlying socket.\n const requestContextValue =\n requestContext.getStore() ?? connectionRequestContext\n const initiator = requestContextValue?.initiator || socket\n\n requestParser = new HttpRequestParser({\n onError: stopParsingRequests,\n connectionOptions: {\n method: httpMethod,\n url: baseUrl,\n },\n /**\n * @note The message boundary ends the current exchange.\n * Schedule the controller reset so the next write on this\n * (kept-alive) socket opens a new exchange and buffers for\n * its own verdict instead of following the settled one\n * (e.g. leaking a mocked request to the server of a\n * previously passed-through exchange).\n */\n onMessageComplete: () => {\n socketController.scheduleReset()\n },\n onRequest: async (parsedRequest, requestAbortController) => {\n const request =\n requestContextValue?.transformRequest?.(parsedRequest) ??\n parsedRequest\n\n /**\n * @note A subsequent request arriving on a kept-alive socket\n * that has already been handled (passed through or mocked).\n * Clients like Undici reuse sockets without emitting the\n * \"free\" event, so reset the controller here, at the HTTP\n * message boundary, to handle the new request from the\n * pending state again.\n */\n if (socketController['readyState'] !== SocketController.PENDING) {\n socketController.reset()\n }\n\n const requestId = createRequestId()\n const requestLogger = requestContextValue?.logger ?? httpLogger\n\n httpLogger.verbose('received a parsed HTTP request %o', {\n method: request.method,\n url: request.url,\n })\n\n const requestController = new RequestController(\n request,\n {\n respondWith: async (rawResponse) => {\n httpLogger.verbose('respondWith() %o', {\n status: rawResponse.status,\n statusText: rawResponse.statusText,\n hasBody: rawResponse.body != null,\n })\n\n /**\n * @note The client may destroy the socket (e.g. on request\n * abort) moments before a response arrives. A destroyed\n * socket cannot be claimed and has no one reading it.\n */\n if (socket.destroyed) {\n return\n }\n\n socketController.claim()\n\n const response = FetchResponse.from(rawResponse, {\n url: request.url,\n })\n\n /**\n * @note A successful mocked response to a \"CONNECT\"\n * request establishes a tunnel to the requested authority\n * (e.g. \"127.0.0.1:80\"). The exchange that follows on this\n * socket is addressed to that authority, not to the proxy.\n */\n if (request.method === 'CONNECT' && response.ok) {\n tunnelUrl = new URL(`http://${request.url}`)\n }\n\n /**\n * @note Clone the response before \"respondWith\" because it will\n * consume its body. This way, we can have a readable response copy\n * for the \"response\" event below.\n */\n const responseClone = isResponseError(response)\n ? null\n : response.clone()\n\n const respond = () => {\n return this.respondWith({\n socket: socketController[kRawSocket],\n request: context.request,\n response,\n })\n }\n\n if (responseClone) {\n await this.emitter.emitAsPromise(\n new HttpResponseEvent({\n initiator,\n requestId,\n request: context.request,\n response: responseClone,\n responseType: 'mock',\n })\n )\n }\n\n if (socket.connecting) {\n // Send a mocked response once the socket connects, just like the real server would.\n // This preserves the correct order of events (e.g. connect, then data).\n socket.once('connect', respond)\n } else {\n /**\n * @note Reused sockets stay connected between requests and will not\n * emit \"connect\" anymore. If that's the case, respond immediately.\n */\n await respond()\n }\n },\n errorWith: (reason) => {\n if (reason instanceof Error) {\n socket.destroy(reason)\n }\n },\n passthrough: () => {\n const realSocket = socketController.passthrough(\n isHttpConnection === false\n ? undefined\n : this.#modifyHttpHeaders(context.request)\n )\n\n if (isHttpConnection === false) {\n return\n }\n\n if (this.emitter.listenerCount('response') > 0) {\n httpLogger.verbose(\n 'found \"response\" listener, corking socket reads'\n )\n\n /**\n * Suspend the delivery of the original response to the client\n * until the \"response\" event listeners settle. This guarantees\n * that the request promise (e.g. `await fetch()`) does not\n * resolve before the listeners are done. The real socket keeps\n * emitting data for the response parser meanwhile.\n */\n socketController.corkReads()\n\n let responseParserDisposed = false\n let responseComplete = false\n let hasFinalResponse = false\n const responseParser = new HttpResponseParser({\n onError: (error) => {\n disposeResponseParser(error)\n socketController.uncorkReads()\n },\n onMessageComplete: (status) => {\n responseComplete = status >= 200 || status === 101\n },\n onResponse: async (response) => {\n hasFinalResponse =\n response.status >= 200 || response.status === 101\n httpLogger.verbose(\n 'HTTP response parser parsed: %d %s',\n response.status,\n response.statusText\n )\n\n if (isResponseError(response)) {\n httpLogger.verbose(\n 'response is an error response, uncorking socket reads...'\n )\n\n socketController.uncorkReads()\n return\n }\n\n FetchResponse.setUrl(request.url, response)\n\n try {\n httpLogger.verbose('emitting \"response\" event')\n await this.emitter.emitAsPromise(\n new HttpResponseEvent({\n initiator,\n requestId,\n request: context.request,\n response,\n responseType: 'original',\n })\n )\n } finally {\n httpLogger.verbose('uncorking socket reads')\n socketController.uncorkReads()\n\n /**\n * @note Informational responses other than\n * \"101 Switching Protocols\" are followed by a final\n * response on the same connection. Keep gating that\n * final response on the \"response\" event listeners.\n */\n if (\n !responseParserDisposed &&\n response.status < 200 &&\n response.status !== 101\n ) {\n socketController.corkReads()\n }\n }\n },\n })\n\n const onResponseData = (chunk: Buffer) => {\n responseParser.execute(chunk)\n\n // Free only after llhttp returns from its callbacks.\n if (responseComplete) {\n disposeResponseParser()\n }\n }\n\n const onResponseClose = () => {\n disposeResponseParser()\n\n // Without a response, no response listener will release\n // the buffered EOF/close that rejects the client request.\n if (!hasFinalResponse) {\n socketController.uncorkReads()\n }\n }\n\n const disposeResponseParser = (error?: Error) => {\n responseParserDisposed = true\n realSocket.removeListener('data', onResponseData)\n realSocket.removeListener('close', onResponseClose)\n responseParser.free(error)\n }\n\n realSocket\n .on('data', onResponseData)\n .once('close', onResponseClose)\n }\n },\n },\n {\n logger: requestLogger,\n requestId,\n }\n )\n\n invariant(\n socketController['readyState'] === SocketController.PENDING,\n 'CANNOT HANDLE ALREADY HANDLED REQUEST',\n request.method,\n request.url,\n socketController['readyState']\n )\n\n /**\n * @note Create a request resolution context.\n * This is so modifications to the \"request\" in upstream interceptors\n * are correctly picked up by the underlying HTTP interceptor.\n */\n const context: HandleRequestOptions = {\n initiator,\n requestId,\n request,\n controller: requestController,\n emitter: this.emitter,\n logger: requestLogger,\n }\n\n /**\n * @note The client destroying the socket while the request\n * is still pending means the request was aborted (e.g. via\n * `AbortController`). Abort the parsed request so its\n * handling settles and late interactions with the request\n * controller become controlled errors.\n */\n abortPendingRequest = () => {\n if (\n requestController.readyState === RequestController.PENDING\n ) {\n requestAbortController.abort()\n }\n }\n\n pendingRequestController = requestController\n\n try {\n await handleRequest(context)\n } finally {\n pendingRequestController = undefined\n abortPendingRequest = undefined\n }\n },\n })\n\n // Forward the first frame to the parser.\n requestParser.execute(toBuffer(chunk))\n })\n\n socket.on('close', () => requestParser?.free())\n },\n {\n signal: controller.signal,\n }\n )\n }\n\n private async respondWith(args: {\n socket: net.Socket\n request: Request\n response: Response\n }): Promise<void> {\n const { socket, request, response } = args\n\n if (socket.destroyed) {\n return\n }\n\n if (isResponseError(response)) {\n /**\n * @note Reference the error response on the socket error so the\n * client-side interceptors (e.g. fetch) can surface it to the\n * consumer as the reason behind the failed request. Keep the\n * reference non-enumerable so the error remains observably\n * identical for the clients that expose it as-is.\n */\n socket.destroy(\n Object.defineProperty(new TypeError('Network error'), kErrorResponse, {\n value: response,\n enumerable: false,\n })\n )\n return\n }\n\n invariant(\n !socket.connecting,\n 'Failed to mock a response for \"%s %s\": socket has not connected',\n request.method,\n request.url\n )\n\n /**\n * Use native server response handling in Node.js.\n * @see https://github.com/nodejs/node/blob/13eb80f3b718452213e0fc449702aefbbfe4110f/lib/_http_server.js#L202\n */\n const incomingMessage = new IncomingMessage(socket)\n\n /**\n * @note Describe the request method so the response body is\n * handled appropriately (e.g. \"HEAD\" responses must not write\n * a body). The HTTP version is deliberately left unset: with it,\n * `ServerResponse` frames bodies of unknown length as chunked,\n * polluting the mocked response headers with \"Transfer-Encoding\"\n * the mock never specified.\n */\n incomingMessage.method = request.method\n\n const serverResponse = new ServerResponse(incomingMessage)\n\n const responseSocket = new net.Socket()\n\n responseSocket._writeGeneric = (writev, data, encoding, callback) => {\n unwrapPendingData(data, (chunk, encoding) => {\n socket.push(toBuffer(chunk), encoding)\n })\n callback?.()\n }\n\n responseSocket._destroy = (\n error: Error | null,\n callback: (error: Error | null) => void\n ) => {\n /**\n * Only destroy the socket on stream errors.\n * On a clean end, the socket is already signaled via `socket.push(null)`\n * in the main response flow. Destroying it here prematurely would prevent\n * the client from processing the response (e.g. calling `response.destroy()`).\n * @see https://github.com/mswjs/interceptors/issues/738\n */\n if (error) {\n socket.destroy()\n }\n\n callback(null)\n }\n\n responseSocket.on('drain', () => serverResponse.emit('drain'))\n serverResponse.assignSocket(responseSocket)\n\n serverResponse.removeHeader('connection')\n serverResponse.removeHeader('date')\n\n const rawResponseHeaders = getRawFetchHeaders(response.headers)\n serverResponse.writeHead(\n response.status,\n response.statusText || STATUS_CODES[response.status],\n rawResponseHeaders\n )\n\n /**\n * @note Override the socket's `_destroy` before writing the response body.\n * The underlying TCP handle (from `socket.connect()`) makes `_destroy` async\n * (`_handle.close()` callback), which delays the 'error' event. Since the real\n * TCP connection is irrelevant for mocked responses, take the synchronous path\n * so that user-initiated `response.destroy(error)` emits the error promptly.\n * This must happen before `serverResponse.end()` because the HTTP parser may\n * fire the 'response' event synchronously during `socket.push()`.\n */\n socket._destroy = function (\n error: Error | null,\n callback: (error: Error | null) => void\n ) {\n if (error) {\n /**\n * Emit the error event as a microtask instead of relying on the default\n * `process.nextTick(emitErrorNT)` from `callback(error)`. This is necessary\n * because `respondWith` runs inside a microtask (from `await reader.read()`).\n * A resolved promise continuation (from toWebResponse) is queued as\n * another microtask during the same phase. Since microtasks are drained before\n * nextTick, the test's `await` would resolve before the error event fires.\n * Using `queueMicrotask` ensures the error event is emitted within the current\n * microtask phase, before other queued microtasks.\n */\n queueMicrotask(() => this.emit('error', error))\n }\n\n callback(null)\n\n /**\n * @note `net.Socket` is constructed with `emitClose: false`, so Node's\n * stream destroy machinery does not emit `'close'` automatically; the\n * stock `net.Socket._destroy` only emits it via `_handle.close()`.\n * Since this override replaces `_destroy`, emit `'close'` here so the\n * mocked socket completes its lifecycle (otherwise consumers waiting\n * on `'close'`, like `http.ClientRequest`, hang).\n */\n process.nextTick(() => this.emit('close', error != null))\n }\n\n if (response.body) {\n const reader = response.body.getReader()\n\n try {\n while (true) {\n const { done, value } = await reader.read()\n\n if (done) {\n serverResponse.end()\n break\n }\n\n if (!serverResponse.write(value)) {\n await new Promise<void>((resolve) => {\n serverResponse.once('drain', resolve)\n })\n }\n }\n } catch {\n /**\n * @note Delay the socket destruction to allow the event loop\n * to flush already-pushed response data (headers + body chunks)\n * through the HTTP parser. Without this, the socket is destroyed\n * on the same tick as `socket.push(data)` and the client never\n * reads the response.\n */\n await new Promise<void>((resolve) => process.nextTick(resolve))\n socket.destroy()\n return\n }\n } else {\n serverResponse.end()\n }\n\n /**\n * @note Self-delimiting responses (chunked, explicit \"Content-Length\",\n * or bodiless by definition) must NOT signal the end-of-stream.\n * The client parser completes them from their framing alone, and\n * ending the socket would kill the kept-alive connection that\n * agents pool and reuse for subsequent requests.\n */\n const isSelfDelimitingResponse =\n request.method === 'HEAD' ||\n response.headers.has('content-length') ||\n response.headers.has('transfer-encoding') ||\n !FetchResponse.isResponseWithBody(response.status)\n\n if (\n /**\n * @note A non-2xx response to a \"CONNECT\" request means the proxy\n * refused the tunnel. Real proxies terminate the connection after\n * sending such a response, regardless of its framing.\n */\n (request.method === 'CONNECT' && !response.ok) ||\n (request.method !== 'CONNECT' && !isSelfDelimitingResponse)\n ) {\n /**\n * @note Defer the end-of-stream signal so the HTTP parser has a chance\n * to process already-pushed response data and fire the 'response' event\n * before the socket is ended. Without this, the parser marks the response\n * as \"complete\" before the client can interact with it (e.g. `response.destroy()`).\n */\n await new Promise<void>((resolve) => process.nextTick(resolve))\n socket.push(null)\n }\n }\n\n #modifyHttpHeaders(request: Request): FlushPendingDataFunction {\n const transformRequestMessage = (\n httpMessage: string | Buffer,\n encoding?: BufferEncoding | 'buffer'\n ): string | Buffer => {\n /**\n * @note Socket can write a buffer (e.g. uploaded file) even before\n * it writes the HTTP message. Bypass those cases.\n */\n if (encoding === 'buffer') {\n return httpMessage\n }\n\n const parts = httpMessage.toString(encoding).split('\\r\\n')\n const headersEndIndex = parts.findIndex((field) => field === '')\n const httpMessageHeaderPairs = parts.slice(1, headersEndIndex)\n\n // Extract raw [name, value] tuples from the wire format so they\n // can be compared against the request's raw fetch headers.\n const httpMessageRawHeaders = httpMessageHeaderPairs.map(\n (line): [string, string] => {\n const separatorIndex = line.indexOf(': ')\n return [line.slice(0, separatorIndex), line.slice(separatorIndex + 2)]\n }\n )\n\n const requestRawHeaders = getRawFetchHeaders(request.headers)\n\n // If the raw headers from the outgoing HTTP message and the request\n // headers are identical, send the message as-is to avoid the cost\n // (and side effects) of reserializing the headers block.\n const headersUnchanged =\n httpMessageRawHeaders.length === requestRawHeaders.length &&\n httpMessageRawHeaders.every((tuple, index) => {\n const requestTuple = requestRawHeaders[index]\n return tuple[0] === requestTuple[0] && tuple[1] === requestTuple[1]\n })\n\n if (headersUnchanged) {\n return httpMessage\n }\n\n const httpMessageHeaders = FetchResponse.parseRawHeaders(\n httpMessageHeaderPairs.flatMap((header) => header.split(': '))\n )\n\n const visitedHeaders = new Set<string>()\n\n for (const [headerName] of requestRawHeaders) {\n const normalizedHeaderName = headerName.toLowerCase()\n\n if (visitedHeaders.has(normalizedHeaderName)) {\n continue\n }\n\n visitedHeaders.add(normalizedHeaderName)\n\n /**\n * @note Forbidden Fetch headers (e.g. Host, Origin, Connection)\n * are stripped from `request.headers` but remain in the raw\n * headers list. Skip them so the original values from the\n * outgoing HTTP message are preserved.\n */\n const headerValue = request.headers.get(headerName)\n if (headerValue === null) {\n continue\n }\n\n // Use the merged value from Headers to correctly handle\n // appended headers (e.g. \"1, 2\" instead of just \"2\").\n httpMessageHeaders.set(headerName, headerValue)\n }\n\n visitedHeaders.clear()\n\n const httpMessageHeadersString = Array.from(httpMessageHeaders)\n .map(([name, value]) => `${name}: ${value}`)\n .join('\\r\\n')\n parts.splice(1, headersEndIndex - 1, httpMessageHeadersString)\n\n return parts.join('\\r\\n')\n }\n\n return (pendingData, encoding, callback) => {\n if (Array.isArray(pendingData)) {\n pendingData[0].chunk = transformRequestMessage(\n pendingData[0].chunk,\n pendingData[0].encoding\n )\n } else {\n pendingData = transformRequestMessage(pendingData, encoding)\n }\n\n callback(pendingData)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,iBAAiB,IAAI,kBAAkC;AAEpE,SAAgB,oBAAuB,UAAmB,QAAoB;;;;;;;CAO5E,IAAI,eAAe,SAAS,GAC1B,OAAO,SAAS;;;;;;;;CAUlB,MAAM,UAA0B;EAC9B,WAAW,KAAA;EACX;CACF;CAEA,OAAO,eAAe,IAAI,eAAe;EACvC,MAAM,YAAY,SAAS;EAC3B,QAAQ,YAAY;EACpB,OAAO;CACT,CAAC;AACH;;;AC9BA,MAAM,SAAS,aAAa,cAAc;AAS1C,SAAgB,kBACd,SACwB;CACxB,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,EAAE,QAAQ,SAAS,WAAW,sBAAsB;CAE1D,OAAO,GACL,WACA,OAAO,UAAU;EACf,IAAI,UAAU,MAAM,SAAS,GAAG;GAC9B,OAAO,QAAQ,mCAAiC,EAC9C,WAAW,MAAM,UACnB,CAAC;GACD,MAAM,QAAQ,cAAc,KAAK;EACnC;CACF,GACA,EACE,QAAQ,WAAW,OACrB,CACF;CAEA,MAAM,mBAGF,OAAO,UAAU;EACnB,IACE,UAAU,MAAM,SAAS,MACxB,qBAAqB,QAAQ,kBAAkB,KAAK,IACrD;GACA,OAAO,QAAQ,oCAAkC;IAC/C,WAAW,MAAM;IACjB,cAAc,MAAM;GACtB,CAAC;GACD,MAAM,QAAQ,cAAc,KAAK;EACnC;CACF;CAEA,MAAM,6BAGF,OAAO,UAAU;EACnB,IAAI,UAAU,MAAM,SAAS,GAAG;GAC9B,OAAO,QAAQ,8CAA4C,EACzD,WAA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ACjB;QAEA,cAAc,wBAAwB,aAAa,QAAQ;GAG7D,SAAS,WAAW;EACtB;CACF;AACF"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { t as Interceptor } from "./interceptor-dtJZ_9QT.js";
|
|
2
|
+
import { TypedEvent } from "rettime";
|
|
3
|
+
//#region src/interceptors/WebSocket/utils/events.d.ts
|
|
4
|
+
declare const kCancelable: unique symbol;
|
|
5
|
+
declare const kDefaultPrevented: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* A `MessageEvent` superset that supports event cancellation
|
|
8
|
+
* in Node.js. It's rather non-intrusive so it can be safely
|
|
9
|
+
* used in the browser as well.
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/nodejs/node/issues/51767
|
|
12
|
+
*/
|
|
13
|
+
declare class CancelableMessageEvent<T = any> extends MessageEvent<T> {
|
|
14
|
+
[kCancelable]: boolean;
|
|
15
|
+
[kDefaultPrevented]: boolean;
|
|
16
|
+
constructor(type: string, init: MessageEventInit<T>);
|
|
17
|
+
get cancelable(): boolean;
|
|
18
|
+
set cancelable(nextCancelable: boolean);
|
|
19
|
+
get defaultPrevented(): boolean;
|
|
20
|
+
set defaultPrevented(nextDefaultPrevented: boolean);
|
|
21
|
+
preventDefault(): void;
|
|
22
|
+
}
|
|
23
|
+
interface CloseEventInit extends EventInit {
|
|
24
|
+
code?: number;
|
|
25
|
+
reason?: string;
|
|
26
|
+
wasClean?: boolean;
|
|
27
|
+
}
|
|
28
|
+
declare class CloseEvent extends Event {
|
|
29
|
+
code: number;
|
|
30
|
+
reason: string;
|
|
31
|
+
wasClean: boolean;
|
|
32
|
+
constructor(type: string, init?: CloseEventInit);
|
|
33
|
+
}
|
|
34
|
+
declare class CancelableCloseEvent extends CloseEvent {
|
|
35
|
+
[kCancelable]: boolean;
|
|
36
|
+
[kDefaultPrevented]: boolean;
|
|
37
|
+
constructor(type: string, init?: CloseEventInit);
|
|
38
|
+
get cancelable(): boolean;
|
|
39
|
+
set cancelable(nextCancelable: boolean);
|
|
40
|
+
get defaultPrevented(): boolean;
|
|
41
|
+
set defaultPrevented(nextDefaultPrevented: boolean);
|
|
42
|
+
preventDefault(): void;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/interceptors/WebSocket/web-socket-transport.d.ts
|
|
46
|
+
type WebSocketData = string | ArrayBuffer | Blob | ArrayBufferView<ArrayBuffer>;
|
|
47
|
+
type WebSocketTransportEventMap = {
|
|
48
|
+
incoming: MessageEvent<WebSocketData>;
|
|
49
|
+
outgoing: MessageEvent<WebSocketData>;
|
|
50
|
+
close: CloseEvent;
|
|
51
|
+
};
|
|
52
|
+
type StrictEventListenerOrEventListenerObject<EventType extends Event> = ((this: WebSocket, event: EventType) => void) | {
|
|
53
|
+
handleEvent(this: WebSocket, event: EventType): void;
|
|
54
|
+
};
|
|
55
|
+
interface WebSocketTransport {
|
|
56
|
+
addEventListener<EventType extends keyof WebSocketTransportEventMap>(event: EventType, listener: StrictEventListenerOrEventListenerObject<WebSocketTransportEventMap[EventType]> | null, options?: boolean | AddEventListenerOptions): void;
|
|
57
|
+
dispatchEvent<EventType extends keyof WebSocketTransportEventMap>(event: WebSocketTransportEventMap[EventType]): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Send the data from the server to this client.
|
|
60
|
+
*/
|
|
61
|
+
send(data: WebSocketData): void;
|
|
62
|
+
/**
|
|
63
|
+
* Close the client connection.
|
|
64
|
+
*/
|
|
65
|
+
close(code?: number, reason?: string): void;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/interceptors/WebSocket/web-socket-override.d.ts
|
|
69
|
+
type WebSocketEventListener<EventType extends WebSocketEventMap[keyof WebSocketEventMap] = Event> = (this: WebSocket, event: EventType) => void;
|
|
70
|
+
declare const kPassthroughPromise: unique symbol;
|
|
71
|
+
declare const kOnSend: unique symbol;
|
|
72
|
+
declare const kClose: unique symbol;
|
|
73
|
+
declare class WebSocketOverride extends EventTarget implements WebSocket {
|
|
74
|
+
static readonly CONNECTING = 0;
|
|
75
|
+
static readonly OPEN = 1;
|
|
76
|
+
static readonly CLOSING = 2;
|
|
77
|
+
static readonly CLOSED = 3;
|
|
78
|
+
readonly CONNECTING = 0;
|
|
79
|
+
readonly OPEN = 1;
|
|
80
|
+
readonly CLOSING = 2;
|
|
81
|
+
readonly CLOSED = 3;
|
|
82
|
+
url: string;
|
|
83
|
+
protocol: string;
|
|
84
|
+
extensions: string;
|
|
85
|
+
binaryType: BinaryType;
|
|
86
|
+
readyState: WebSocket['readyState'];
|
|
87
|
+
bufferedAmount: number;
|
|
88
|
+
private _onopen;
|
|
89
|
+
private _onmessage;
|
|
90
|
+
private _onerror;
|
|
91
|
+
private _onclose;
|
|
92
|
+
private [kPassthroughPromise];
|
|
93
|
+
private [kOnSend]?;
|
|
94
|
+
constructor(url: string | URL, protocols?: string | Array<string>);
|
|
95
|
+
set onopen(listener: WebSocketEventListener | null);
|
|
96
|
+
get onopen(): WebSocketEventListener | null;
|
|
97
|
+
set onmessage(listener: WebSocketEventListener<MessageEvent<WebSocketData>> | null);
|
|
98
|
+
get onmessage(): WebSocketEventListener<MessageEvent<WebSocketData>> | null;
|
|
99
|
+
set onerror(listener: WebSocketEventListener | null);
|
|
100
|
+
get onerror(): WebSocketEventListener | null;
|
|
101
|
+
set onclose(listener: WebSocketEventListener<CloseEvent> | null);
|
|
102
|
+
get onclose(): WebSocketEventListener<CloseEvent> | null;
|
|
103
|
+
/**
|
|
104
|
+
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
105
|
+
*/
|
|
106
|
+
send(data: WebSocketData): void;
|
|
107
|
+
close(code?: number, reason?: string): void;
|
|
108
|
+
private [kClose];
|
|
109
|
+
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, event: WebSocketEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
110
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
111
|
+
removeEventListener<K extends keyof WebSocketEventMap>(type: K, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/interceptors/WebSocket/web-socket-client-connection.d.ts
|
|
115
|
+
declare const kEmitter$1: unique symbol;
|
|
116
|
+
interface WebSocketClientEventMap {
|
|
117
|
+
message: MessageEvent<WebSocketData>;
|
|
118
|
+
close: CloseEvent;
|
|
119
|
+
}
|
|
120
|
+
declare abstract class WebSocketClientConnectionProtocol {
|
|
121
|
+
abstract id: string;
|
|
122
|
+
abstract url: URL;
|
|
123
|
+
abstract send(data: WebSocketData): void;
|
|
124
|
+
abstract close(code?: number, reason?: string): void;
|
|
125
|
+
abstract addEventListener<EventType extends keyof WebSocketClientEventMap>(type: EventType, listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>, options?: AddEventListenerOptions | boolean): void;
|
|
126
|
+
abstract removeEventListener<EventType extends keyof WebSocketClientEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>, options?: EventListenerOptions | boolean): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The WebSocket client instance represents an incoming
|
|
130
|
+
* client connection. The user can control the connection,
|
|
131
|
+
* send and receive events.
|
|
132
|
+
*/
|
|
133
|
+
declare class WebSocketClientConnection implements WebSocketClientConnectionProtocol {
|
|
134
|
+
readonly socket: WebSocket;
|
|
135
|
+
private readonly transport;
|
|
136
|
+
readonly id: string;
|
|
137
|
+
readonly url: URL;
|
|
138
|
+
private [kEmitter$1];
|
|
139
|
+
constructor(socket: WebSocket, transport: WebSocketTransport);
|
|
140
|
+
/**
|
|
141
|
+
* Listen for the outgoing events from the connected WebSocket client.
|
|
142
|
+
*/
|
|
143
|
+
addEventListener<EventType extends keyof WebSocketClientEventMap>(type: EventType, listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>, options?: AddEventListenerOptions | boolean): void;
|
|
144
|
+
/**
|
|
145
|
+
* Removes the listener for the given event.
|
|
146
|
+
*/
|
|
147
|
+
removeEventListener<EventType extends keyof WebSocketClientEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketClientEventMap[EventType]>, options?: EventListenerOptions | boolean): void;
|
|
148
|
+
/**
|
|
149
|
+
* Send data to the connected client.
|
|
150
|
+
*/
|
|
151
|
+
send(data: WebSocketData): void;
|
|
152
|
+
/**
|
|
153
|
+
* Close the WebSocket connection.
|
|
154
|
+
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
155
|
+
* @param {string} reason A custom connection close reason.
|
|
156
|
+
*/
|
|
157
|
+
close(code?: number, reason?: string): void;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/interceptors/WebSocket/web-socket-class-transport.d.ts
|
|
161
|
+
/**
|
|
162
|
+
* Abstraction over the given mock `WebSocket` instance that allows
|
|
163
|
+
* for controlling that instance (e.g. sending and receiving messages).
|
|
164
|
+
*/
|
|
165
|
+
declare class WebSocketClassTransport extends EventTarget implements WebSocketTransport {
|
|
166
|
+
protected readonly socket: WebSocketOverride;
|
|
167
|
+
constructor(socket: WebSocketOverride);
|
|
168
|
+
addEventListener<EventType extends keyof WebSocketTransportEventMap>(type: EventType, callback: StrictEventListenerOrEventListenerObject<WebSocketTransportEventMap[EventType]> | null, options?: boolean | AddEventListenerOptions): void;
|
|
169
|
+
dispatchEvent<EventType extends keyof WebSocketTransportEventMap>(event: WebSocketTransportEventMap[EventType]): boolean;
|
|
170
|
+
send(data: WebSocketData): void;
|
|
171
|
+
close(code: number, reason?: string): void;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/interceptors/WebSocket/web-socket-server-connection.d.ts
|
|
175
|
+
declare const kEmitter: unique symbol;
|
|
176
|
+
declare const kSend: unique symbol;
|
|
177
|
+
interface WebSocketServerEventMap {
|
|
178
|
+
open: Event;
|
|
179
|
+
message: MessageEvent<WebSocketData>;
|
|
180
|
+
error: Event;
|
|
181
|
+
close: CloseEvent;
|
|
182
|
+
}
|
|
183
|
+
declare abstract class WebSocketServerConnectionProtocol {
|
|
184
|
+
abstract connect(): void;
|
|
185
|
+
abstract send(data: WebSocketData): void;
|
|
186
|
+
abstract close(): void;
|
|
187
|
+
abstract addEventListener<EventType extends keyof WebSocketServerEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>, options?: AddEventListenerOptions | boolean): void;
|
|
188
|
+
abstract removeEventListener<EventType extends keyof WebSocketServerEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>, options?: EventListenerOptions | boolean): void;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The WebSocket server instance represents the actual production
|
|
192
|
+
* WebSocket server connection. It's idle by default but you can
|
|
193
|
+
* establish it by calling `server.connect()`.
|
|
194
|
+
*/
|
|
195
|
+
declare class WebSocketServerConnection implements WebSocketServerConnectionProtocol {
|
|
196
|
+
private readonly client;
|
|
197
|
+
private readonly transport;
|
|
198
|
+
private readonly createConnection;
|
|
199
|
+
/**
|
|
200
|
+
* A WebSocket instance connected to the original server.
|
|
201
|
+
*/
|
|
202
|
+
private realWebSocket?;
|
|
203
|
+
private mockCloseController;
|
|
204
|
+
private realCloseController;
|
|
205
|
+
private [kEmitter];
|
|
206
|
+
constructor(client: WebSocketOverride, transport: WebSocketClassTransport, createConnection: () => WebSocket);
|
|
207
|
+
/**
|
|
208
|
+
* The `WebSocket` instance connected to the original server.
|
|
209
|
+
* Accessing this before calling `server.connect()` will throw.
|
|
210
|
+
*/
|
|
211
|
+
get socket(): WebSocket;
|
|
212
|
+
/**
|
|
213
|
+
* Open connection to the original WebSocket server.
|
|
214
|
+
*/
|
|
215
|
+
connect(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Listen for the incoming events from the original WebSocket server.
|
|
218
|
+
*/
|
|
219
|
+
addEventListener<EventType extends keyof WebSocketServerEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>, options?: AddEventListenerOptions | boolean): void;
|
|
220
|
+
/**
|
|
221
|
+
* Remove the listener for the given event.
|
|
222
|
+
*/
|
|
223
|
+
removeEventListener<EventType extends keyof WebSocketServerEventMap>(event: EventType, listener: WebSocketEventListener<WebSocketServerEventMap[EventType]>, options?: EventListenerOptions | boolean): void;
|
|
224
|
+
/**
|
|
225
|
+
* Send data to the original WebSocket server.
|
|
226
|
+
* @example
|
|
227
|
+
* server.send('hello')
|
|
228
|
+
* server.send(new Blob(['hello']))
|
|
229
|
+
* server.send(new TextEncoder().encode('hello'))
|
|
230
|
+
*/
|
|
231
|
+
send(data: WebSocketData): void;
|
|
232
|
+
private [kSend];
|
|
233
|
+
/**
|
|
234
|
+
* Close the actual server connection.
|
|
235
|
+
*/
|
|
236
|
+
close(): void;
|
|
237
|
+
private handleIncomingMessage;
|
|
238
|
+
private handleMockClose;
|
|
239
|
+
private handleRealClose;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/interceptors/WebSocket/index.d.ts
|
|
243
|
+
/**
|
|
244
|
+
* Intercept the outgoing WebSocket connections created using
|
|
245
|
+
* the global `WebSocket` class.
|
|
246
|
+
*/
|
|
247
|
+
declare class WebSocketInterceptor extends Interceptor<WebSocketEventMap$1> {
|
|
248
|
+
static symbol: symbol;
|
|
249
|
+
protected predicate(): boolean;
|
|
250
|
+
protected setup(): void;
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/events/websocket.d.ts
|
|
254
|
+
/**
|
|
255
|
+
* The connection information.
|
|
256
|
+
*/
|
|
257
|
+
interface WebSocketConnectionInfo {
|
|
258
|
+
/**
|
|
259
|
+
* The protocols supported by the WebSocket client.
|
|
260
|
+
*/
|
|
261
|
+
protocols: string | Array<string> | undefined;
|
|
262
|
+
}
|
|
263
|
+
interface WebSocketConnectionEventData {
|
|
264
|
+
/**
|
|
265
|
+
* The incoming WebSocket client connection.
|
|
266
|
+
*/
|
|
267
|
+
client: WebSocketClientConnection;
|
|
268
|
+
/**
|
|
269
|
+
* The original WebSocket server connection.
|
|
270
|
+
*/
|
|
271
|
+
server: WebSocketServerConnection;
|
|
272
|
+
info: WebSocketConnectionInfo;
|
|
273
|
+
}
|
|
274
|
+
declare class WebSocketConnectionEvent<DataType extends WebSocketConnectionEventData = WebSocketConnectionEventData> extends TypedEvent<DataType, void, 'connection'> {
|
|
275
|
+
client: WebSocketClientConnection;
|
|
276
|
+
server: WebSocketServerConnection;
|
|
277
|
+
info: WebSocketConnectionInfo;
|
|
278
|
+
constructor(data: DataType);
|
|
279
|
+
}
|
|
280
|
+
type WebSocketEventMap$1 = {
|
|
281
|
+
connection: WebSocketConnectionEvent;
|
|
282
|
+
};
|
|
283
|
+
//#endregion
|
|
284
|
+
export { WebSocketServerConnectionProtocol as a, WebSocketClientConnectionProtocol as c, WebSocketTransport as d, CancelableCloseEvent as f, WebSocketServerConnection as i, WebSocketClientEventMap as l, CloseEvent as m, WebSocketEventMap$1 as n, WebSocketServerEventMap as o, CancelableMessageEvent as p, WebSocketInterceptor as r, WebSocketClientConnection as s, WebSocketConnectionEvent as t, WebSocketData as u };
|
|
285
|
+
//# sourceMappingURL=websocket-CC0nB0md.d.ts.map
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@mswjs/interceptors",
|
|
4
4
|
"description": "Low-level network interception library for Node.js.",
|
|
5
|
-
"version": "0.42.
|
|
5
|
+
"version": "0.42.4",
|
|
6
6
|
"main": "./lib/node/index.js",
|
|
7
7
|
"types": "./lib/node/index.d.ts",
|
|
8
8
|
"exports": {
|
|
@@ -34,7 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./fetch/node": "./lib/node/interceptors/fetch/node.js",
|
|
36
36
|
"./fetch/web": "./lib/browser/interceptors/fetch/web.js",
|
|
37
|
-
"./WebSocket":
|
|
37
|
+
"./WebSocket": {
|
|
38
|
+
"browser": "./lib/browser/interceptors/WebSocket/index.js",
|
|
39
|
+
"default": "./lib/node/interceptors/WebSocket/index.js"
|
|
40
|
+
},
|
|
38
41
|
"./RemoteHttpInterceptor": {
|
|
39
42
|
"browser": null,
|
|
40
43
|
"default": "./lib/node/remote-http-interceptor.js"
|
|
@@ -23,6 +23,7 @@ import { bindEvent } from './utils/bind-event'
|
|
|
23
23
|
import { hasConfigurableGlobal } from '../../utils/has-configurable-global'
|
|
24
24
|
import { patchesRegistry } from '../../utils/patches-registry'
|
|
25
25
|
import { createLogger } from '../../utils/logger'
|
|
26
|
+
import { runAsInternalConnection } from '../../utils/internal-connection'
|
|
26
27
|
|
|
27
28
|
export {
|
|
28
29
|
type WebSocketData,
|
|
@@ -73,7 +74,9 @@ export class WebSocketInterceptor extends Interceptor<WebSocketEventMap> {
|
|
|
73
74
|
})
|
|
74
75
|
|
|
75
76
|
const createConnection = (): WebSocket => {
|
|
76
|
-
return
|
|
77
|
+
return runAsInternalConnection(() => {
|
|
78
|
+
return Reflect.construct(target, args, newTarget)
|
|
79
|
+
})
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
// All WebSocket instances are mocked and don't forward
|
|
@@ -29,6 +29,7 @@ const KIND_RESPONSE = constants.TYPE.RESPONSE
|
|
|
29
29
|
type ParserKind = typeof KIND_REQUEST | typeof KIND_RESPONSE
|
|
30
30
|
|
|
31
31
|
export interface ParserCallbacks<K extends ParserKind> {
|
|
32
|
+
onError?: (error: Error) => void
|
|
32
33
|
onMessageBegin?: () => number | void
|
|
33
34
|
onHeadersComplete?: (
|
|
34
35
|
info: K extends typeof KIND_REQUEST
|
|
@@ -305,6 +306,13 @@ export class HttpParser<K extends ParserKind> {
|
|
|
305
306
|
const buffer = new Uint8Array(llhttp_memory.buffer)
|
|
306
307
|
const length = buffer.indexOf(0, errorPointer) - errorPointer
|
|
307
308
|
|
|
308
|
-
|
|
309
|
+
const error = new Error(readStringFrom(errorPointer, length))
|
|
310
|
+
|
|
311
|
+
if (this[kCallbacks].onError) {
|
|
312
|
+
this[kCallbacks].onError(error)
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
throw error
|
|
309
317
|
}
|
|
310
318
|
}
|