diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index f5def93d128264..f2a114f9c7ac0d 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -1552,6 +1552,89 @@ JSC_DEFINE_HOST_FUNCTION(jsTTYSetMode, (JSC::JSGlobalObject * globalObject, Call return JSValue::encode(jsNumber(err)); } +JSC_DEFINE_HOST_FUNCTION(jsHTTPGetHeader, (JSGlobalObject * globalObject, CallFrame* callFrame)) +{ + auto& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + JSValue headersValue = callFrame->argument(0); + + if (auto* headers = jsDynamicCast(headersValue)) { + JSValue nameValue = callFrame->argument(1); + if (nameValue.isString()) { + FetchHeaders* impl = &headers->wrapped(); + String name = nameValue.toWTFString(globalObject); + if (WTF::equalIgnoringASCIICase(name, "set-cookie"_s)) { + return fetchHeadersGetSetCookie(globalObject, vm, impl); + } + + WebCore::ExceptionOr res = impl->get(name); + if (res.hasException()) { + WebCore::propagateException(globalObject, scope, res.releaseException()); + return JSValue::encode(jsUndefined()); + } + + String value = res.returnValue(); + if (value.isEmpty()) { + return JSValue::encode(jsUndefined()); + } + + return JSC::JSValue::encode(jsString(vm, value)); + } + } + + return JSValue::encode(jsUndefined()); +} + +JSC_DEFINE_HOST_FUNCTION(jsHTTPSetHeader, (JSGlobalObject * globalObject, CallFrame* callFrame)) +{ + auto& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + JSValue headersValue = callFrame->argument(0); + + if (auto* headers = jsDynamicCast(headersValue)) { + JSValue nameValue = callFrame->argument(1); + if (nameValue.isString()) { + String name = nameValue.toWTFString(globalObject).convertToASCIILowercase(); + FetchHeaders* impl = &headers->wrapped(); + + JSValue valueValue = callFrame->argument(2); + if (valueValue.isUndefined()) + return JSValue::encode(jsUndefined()); + + if (isArray(globalObject, valueValue)) { + auto* array = jsCast(valueValue); + unsigned length = array->length(); + if (length > 0) { + JSValue item = array->getIndex(globalObject, 0); + if (UNLIKELY(scope.exception())) + return JSValue::encode(jsUndefined()); + impl->set(name, item.getString(globalObject)); + RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined())); + } + for (unsigned i = 1; i < length; ++i) { + JSValue value = array->getIndex(globalObject, i); + if (UNLIKELY(scope.exception())) + return JSValue::encode(jsUndefined()); + if (!value.isString()) + continue; + impl->append(name, value.getString(globalObject)); + RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined())); + } + RELEASE_AND_RETURN(scope, JSValue::encode(jsUndefined())); + return JSValue::encode(jsUndefined()); + } + + impl->set(name, valueValue.getString(globalObject)); + RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined())); + return JSValue::encode(jsUndefined()); + } + } + + return JSValue::encode(jsUndefined()); +} + JSC_DEFINE_CUSTOM_GETTER(noop_getter, (JSGlobalObject*, EncodedJSValue, PropertyName)) { return JSC::JSValue::encode(JSC::jsUndefined()); @@ -1686,6 +1769,17 @@ static JSC_DEFINE_HOST_FUNCTION(functionLazyLoad, return JSC::JSValue::encode(JSSQLStatementConstructor::create(vm, globalObject, JSSQLStatementConstructor::createStructure(vm, globalObject, globalObject->m_functionPrototype.get()))); } + if (string == "http"_s) { + auto* obj = constructEmptyObject(globalObject); + obj->putDirect( + vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "setHeader"_s)), + JSC::JSFunction::create(vm, globalObject, 3, "setHeader"_s, jsHTTPSetHeader, ImplementationVisibility::Public), NoIntrinsic); + obj->putDirect( + vm, JSC::PropertyName(JSC::Identifier::fromString(vm, "getHeader"_s)), + JSC::JSFunction::create(vm, globalObject, 2, "getHeader"_s, jsHTTPGetHeader, ImplementationVisibility::Public), NoIntrinsic); + return JSC::JSValue::encode(obj); + } + if (string == "worker_threads"_s) { JSValue workerData = jsUndefined(); diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp index 2ae8dd5472c703..9cd5933806cb03 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp @@ -245,17 +245,11 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getAll, (JSGlobalObject return JSValue::encode(array); } -JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getSetCookie, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +JSC_DEFINE_HOST_FUNCTION(fetchHeadersGetSetCookie, (JSC::JSGlobalObject * lexicalGlobalObject, VM& vm, WebCore::FetchHeaders* impl)) { - auto& vm = JSC::getVM(lexicalGlobalObject); auto scope = DECLARE_THROW_SCOPE(vm); - JSFetchHeaders* castedThis = jsDynamicCast(callFrame->thisValue()); - if (UNLIKELY(!castedThis)) { - return JSValue::encode(jsUndefined()); - } - auto& impl = castedThis->wrapped(); - auto values = impl.getSetCookieHeaders(); + auto values = impl->getSetCookieHeaders(); unsigned count = values.size(); if (!count) { @@ -263,20 +257,31 @@ JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getSetCookie, (JSGlobal } JSC::JSArray* array = constructEmptyArray(lexicalGlobalObject, nullptr, count); - RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined())); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); if (UNLIKELY(!array)) { throwOutOfMemoryError(lexicalGlobalObject, scope); - return JSValue::encode(jsUndefined()); + return encodedJSValue(); } for (unsigned i = 0; i < count; ++i) { array->putDirectIndex(lexicalGlobalObject, i, jsString(vm, values[i])); - RETURN_IF_EXCEPTION(scope, JSValue::encode(jsUndefined())); + RETURN_IF_EXCEPTION(scope, encodedJSValue()); } return JSValue::encode(array); } +JSC_DEFINE_HOST_FUNCTION(jsFetchHeadersPrototypeFunction_getSetCookie, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) +{ + auto& vm = JSC::getVM(lexicalGlobalObject); + JSFetchHeaders* castedThis = jsDynamicCast(callFrame->thisValue()); + if (UNLIKELY(!castedThis)) { + return JSValue::encode(jsUndefined()); + } + auto& impl = castedThis->wrapped(); + return fetchHeadersGetSetCookie(lexicalGlobalObject, vm, &impl); +} + /* Hash table for prototype */ static const HashTableValue JSFetchHeadersPrototypeTableValues[] = { @@ -688,7 +693,6 @@ extern void* _ZTVN7WebCore12FetchHeadersE[]; JSC::JSValue toJSNewlyCreated(JSC::JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref&& impl) { - if constexpr (std::is_polymorphic_v) { #if ENABLE(BINDING_INTEGRITY) const void* actualVTablePointer = getVTablePointer(impl.ptr()); diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.h b/src/bun.js/bindings/webcore/JSFetchHeaders.h index 4efcc5f5fbce26..58b61bbbb800ce 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.h +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.h @@ -97,4 +97,6 @@ template<> struct JSDOMWrapperConverterTraits { using ToWrappedReturnType = FetchHeaders*; }; +JSC::EncodedJSValue fetchHeadersGetSetCookie(JSC::JSGlobalObject* lexicalGlobalObject, VM& vm, WebCore::FetchHeaders* impl); + } // namespace WebCore diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 70ee6ceadb7111..7d5cd6e39616d8 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -2,6 +2,7 @@ const EventEmitter = require("node:events"); const { isTypedArray } = require("node:util/types"); const { Duplex, Readable, Writable } = require("node:stream"); +const { getHeader, setHeader } = $lazy("http"); const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/; /** @@ -75,13 +76,9 @@ const searchParamsSymbol = Symbol.for("query"); // This is the symbol used in No const StringPrototypeSlice = String.prototype.slice; const StringPrototypeStartsWith = String.prototype.startsWith; const StringPrototypeToUpperCase = String.prototype.toUpperCase; -const StringPrototypeIncludes = String.prototype.includes; -const StringPrototypeCharCodeAt = String.prototype.charCodeAt; -const StringPrototypeIndexOf = String.prototype.indexOf; const ArrayIsArray = Array.isArray; const RegExpPrototypeExec = RegExp.prototype.exec; const ObjectAssign = Object.assign; -const ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty; const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/; const NODE_HTTP_WARNING = @@ -126,12 +123,6 @@ function validateFunction(callable: any, field: string) { return callable; } -function getHeader(headers, name) { - if (!headers) return; - const result = headers.get(name); - return result == null ? undefined : result; -} - type FakeSocket = InstanceType; var FakeSocket = class Socket extends Duplex { [kInternalSocketData]: any; @@ -958,8 +949,11 @@ let OriginalWriteHeadFn, OriginalImplicitHeadFn; class ServerResponse extends Writable { declare _writableState: any; - constructor({ req, reply }) { + constructor(c) { super(); + if (!c) c = {}; + var req = c.req || {}; + var reply = c.reply; this.req = req; this._reply = reply; this.sendDate = true; @@ -1174,7 +1168,7 @@ class ServerResponse extends Writable { setHeader(name, value) { var headers = (this.#headers ??= new Headers()); - headers.set(name, value); + setHeader(headers, name, value); return this; } diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h index 9d5cfaf4dbffcb..8b52733500c862 100644 --- a/src/js/out/InternalModuleRegistryConstants.h +++ b/src/js/out/InternalModuleRegistryConstants.h @@ -90,7 +90,7 @@ static constexpr ASCIILiteral NodeFSPromisesCode = "(function (){\"use strict\"; // // -static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, getHeader = function(headers, name) {\n if (!headers)\n return;\n const result = headers.get(name);\n return result == null \? @undefined : result;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, StringPrototypeIncludes = @String.prototype.includes, StringPrototypeCharCodeAt = @String.prototype.charCodeAt, StringPrototypeIndexOf = @String.prototype.indexOf, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign;\nvar INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor({ req, reply }) {\n super();\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), { getHeader, setHeader } = @lazy(\"http\"), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign, INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor(c) {\n super();\n if (!c)\n c = {};\n var req = c.req || {}, reply = c.reply;\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return setHeader(headers, name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; // // @@ -331,7 +331,7 @@ static constexpr ASCIILiteral NodeFSPromisesCode = "(function (){\"use strict\"; // // -static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, getHeader = function(headers, name) {\n if (!headers)\n return;\n const result = headers.get(name);\n return result == null \? @undefined : result;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, StringPrototypeIncludes = @String.prototype.includes, StringPrototypeCharCodeAt = @String.prototype.charCodeAt, StringPrototypeIndexOf = @String.prototype.indexOf, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign;\nvar INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor({ req, reply }) {\n super();\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), { getHeader, setHeader } = @lazy(\"http\"), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign, INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor(c) {\n super();\n if (!c)\n c = {};\n var req = c.req || {}, reply = c.reply;\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return setHeader(headers, name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; // // @@ -573,7 +573,7 @@ static constexpr ASCIILiteral NodeFSPromisesCode = "(function (){\"use strict\"; // // -static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, getHeader = function(headers, name) {\n if (!headers)\n return;\n const result = headers.get(name);\n return result == null \? @undefined : result;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, StringPrototypeIncludes = @String.prototype.includes, StringPrototypeCharCodeAt = @String.prototype.charCodeAt, StringPrototypeIndexOf = @String.prototype.indexOf, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign;\nvar INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor({ req, reply }) {\n super();\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeHttpCode = "(function (){\"use strict\";// src/js/out/tmp/node/http.ts\nvar checkInvalidHeaderChar = function(val) {\n return RegExpPrototypeExec.call(headerCharRegex, val) !== null;\n}, isIPv6 = function(input) {\n return new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\").test(input);\n}, isValidTLSArray = function(obj) {\n if (typeof obj === \"string\" || isTypedArray(obj) || obj instanceof @ArrayBuffer || obj instanceof Blob)\n return !0;\n if (@Array.isArray(obj)) {\n for (var i = 0;i < obj.length; i++)\n if (typeof obj !== \"string\" && !isTypedArray(obj) && !(obj instanceof @ArrayBuffer) && !(obj instanceof Blob))\n return !1;\n return !0;\n }\n}, validateMsecs = function(numberlike, field) {\n if (typeof numberlike !== \"number\" || numberlike < 0)\n throw new ERR_INVALID_ARG_TYPE(field, \"number\", numberlike);\n return numberlike;\n}, validateFunction = function(callable, field) {\n if (typeof callable !== \"function\")\n throw new ERR_INVALID_ARG_TYPE(field, \"Function\", callable);\n return callable;\n}, createServer = function(options, callback) {\n return new Server(options, callback);\n}, emitListeningNextTick = function(self, onListen, err, hostname, port) {\n if (typeof onListen === \"function\")\n try {\n onListen(err, hostname, port);\n } catch (err2) {\n self.emit(\"error\", err2);\n }\n if (self.listening = !err, err)\n self.emit(\"error\", err);\n else\n self.emit(\"listening\", hostname, port);\n}, assignHeaders = function(object, req) {\n var headers = req.headers.toJSON();\n const rawHeaders = @newArrayWithSize(req.headers.count * 2);\n var i = 0;\n for (let key in headers)\n rawHeaders[i++] = key, rawHeaders[i++] = headers[key];\n object.headers = headers, object.rawHeaders = rawHeaders;\n};\nvar getDefaultHTTPSAgent = function() {\n return _defaultHTTPSAgent \?\?= new Agent({ defaultPort: 443, protocol: \"https:\" });\n};\nvar urlToHttpOptions = function(url) {\n var { protocol, hostname, hash, search, pathname, href, port, username, password } = url;\n return {\n protocol,\n hostname: typeof hostname === \"string\" && StringPrototypeStartsWith.call(hostname, \"[\") \? StringPrototypeSlice.call(hostname, 1, -1) : hostname,\n hash,\n search,\n pathname,\n path: `${pathname || \"\"}${search || \"\"}`,\n href,\n port: port \? Number(port) : protocol === \"https:\" \? 443 : protocol === \"http:\" \? 80 : @undefined,\n auth: username || password \? `${decodeURIComponent(username)}:${decodeURIComponent(password)}` : @undefined\n };\n}, validateHost = function(host, name) {\n if (host !== null && host !== @undefined && typeof host !== \"string\")\n throw new Error(\"Invalid arg type in options\");\n return host;\n}, checkIsHttpToken = function(val) {\n return RegExpPrototypeExec.call(tokenRegExp, val) !== null;\n};\nvar _writeHead = function(statusCode, reason, obj, response) {\n if (statusCode |= 0, statusCode < 100 || statusCode > 999)\n throw new Error(\"status code must be between 100 and 999\");\n if (typeof reason === \"string\")\n response.statusMessage = reason;\n else {\n if (!response.statusMessage)\n response.statusMessage = STATUS_CODES[statusCode] || \"unknown\";\n obj = reason;\n }\n response.statusCode = statusCode;\n {\n let k;\n if (@Array.isArray(obj)) {\n if (obj.length % 2 !== 0)\n throw new Error(\"raw headers must have an even number of elements\");\n for (let n = 0;n < obj.length; n += 2)\n if (k = obj[n + 0], k)\n response.setHeader(k, obj[n + 1]);\n } else if (obj) {\n const keys = Object.keys(obj);\n for (let i = 0;i < keys.length; i++)\n if (k = keys[i], k)\n response.setHeader(k, obj[k]);\n }\n }\n if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)\n response._hasBody = !1;\n}, request = function(url, options, cb) {\n return new ClientRequest(url, options, cb);\n}, get = function(url, options, cb) {\n const req = request(url, options, cb);\n return req.end(), req;\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), { isTypedArray } = @requireNativeModule(\"util/types\"), { Duplex, Readable, Writable } = @getInternalField(@internalModuleRegistry, 37) || @createInternalModuleById(37), { getHeader, setHeader } = @lazy(\"http\"), headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/, validateHeaderName = (name, label) => {\n if (typeof name !== \"string\" || !name || !checkIsHttpToken(name))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN\");\n}, validateHeaderValue = (name, value) => {\n if (value === @undefined)\n throw new Error(\"ERR_HTTP_INVALID_HEADER_VALUE\");\n if (checkInvalidHeaderChar(value))\n throw new Error(\"ERR_INVALID_CHAR\");\n}, { URL } = globalThis, globalReportError = globalThis.reportError, setTimeout = globalThis.setTimeout, fetch = Bun.fetch;\nvar kEmptyObject = Object.freeze(Object.create(null)), kOutHeaders = Symbol.for(\"kOutHeaders\"), kEndCalled = Symbol.for(\"kEndCalled\"), kAbortController = Symbol.for(\"kAbortController\"), kClearTimeout = Symbol(\"kClearTimeout\"), kCorked = Symbol.for(\"kCorked\"), searchParamsSymbol = Symbol.for(\"query\"), StringPrototypeSlice = @String.prototype.slice, StringPrototypeStartsWith = @String.prototype.startsWith, StringPrototypeToUpperCase = @String.prototype.toUpperCase, ArrayIsArray = @Array.isArray, RegExpPrototypeExec = @RegExp.prototype.exec, ObjectAssign = Object.assign, INVALID_PATH_REGEX = /[^\\u0021-\\u00ff]/;\nvar _defaultHTTPSAgent, kInternalRequest = Symbol(\"kInternalRequest\"), kInternalSocketData = Symbol.for(\"::bunternal::\"), kEmptyBuffer = @Buffer.alloc(0);\n\nclass ERR_INVALID_ARG_TYPE extends TypeError {\n constructor(name, expected, actual) {\n super(`The ${name} argument must be of type ${expected}. Received type ${typeof actual}`);\n this.code = \"ERR_INVALID_ARG_TYPE\";\n }\n}\nvar FakeSocket = class Socket extends Duplex {\n [kInternalSocketData];\n bytesRead = 0;\n bytesWritten = 0;\n connecting = !1;\n remoteAddress = null;\n remotePort;\n timeout = 0;\n isServer = !1;\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n connect(port, host, connectListener) {\n return this;\n }\n _destroy(err, callback) {\n }\n _final(callback) {\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return 80;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n return this;\n }\n unref() {\n }\n _write(chunk, encoding, callback) {\n }\n};\n\nclass Agent extends EventEmitter {\n defaultPort = 80;\n protocol = \"http:\";\n options;\n requests;\n sockets;\n freeSockets;\n keepAliveMsecs;\n keepAlive;\n maxSockets;\n maxFreeSockets;\n scheduling;\n maxTotalSockets;\n totalSocketCount;\n #fakeSocket;\n static get globalAgent() {\n return globalAgent;\n }\n static get defaultMaxSockets() {\n return @Infinity;\n }\n constructor(options = kEmptyObject) {\n super();\n if (this.options = options = { ...options, path: null }, options.noDelay === @undefined)\n options.noDelay = !0;\n this.requests = kEmptyObject, this.sockets = kEmptyObject, this.freeSockets = kEmptyObject, this.keepAliveMsecs = options.keepAliveMsecs || 1000, this.keepAlive = options.keepAlive || !1, this.maxSockets = options.maxSockets || Agent.defaultMaxSockets, this.maxFreeSockets = options.maxFreeSockets || 256, this.scheduling = options.scheduling || \"lifo\", this.maxTotalSockets = options.maxTotalSockets, this.totalSocketCount = 0, this.defaultPort = options.defaultPort || 80, this.protocol = options.protocol || \"http:\";\n }\n createConnection() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n getName(options = kEmptyObject) {\n let name = `http:${options.host || \"localhost\"}:`;\n if (options.port)\n name += options.port;\n if (name += \":\", options.localAddress)\n name += options.localAddress;\n if (options.family === 4 || options.family === 6)\n name += `:${options.family}`;\n if (options.socketPath)\n name += `:${options.socketPath}`;\n return name;\n }\n addRequest() {\n }\n createSocket(req, options, cb) {\n cb(null, this.#fakeSocket \?\?= new FakeSocket);\n }\n removeSocket() {\n }\n keepSocketAlive() {\n return !0;\n }\n reuseSocket() {\n }\n destroy() {\n }\n}\n\nclass Server extends EventEmitter {\n #server;\n #options;\n #tls;\n #is_tls = !1;\n listening = !1;\n serverName;\n constructor(options, callback) {\n super();\n if (typeof options === \"function\")\n callback = options, options = {};\n else if (options == null || typeof options === \"object\") {\n options = { ...options }, this.#tls = null;\n let key = options.key;\n if (key) {\n if (!isValidTLSArray(key))\n @throwTypeError(\"key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let cert = options.cert;\n if (cert) {\n if (!isValidTLSArray(cert))\n @throwTypeError(\"cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let ca = options.ca;\n if (ca) {\n if (!isValidTLSArray(ca))\n @throwTypeError(\"ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile\");\n this.#is_tls = !0;\n }\n let passphrase = options.passphrase;\n if (passphrase && typeof passphrase !== \"string\")\n @throwTypeError(\"passphrase argument must be an string\");\n let serverName = options.servername;\n if (serverName && typeof serverName !== \"string\")\n @throwTypeError(\"servername argument must be an string\");\n let secureOptions = options.secureOptions || 0;\n if (secureOptions && typeof secureOptions !== \"number\")\n @throwTypeError(\"secureOptions argument must be an number\");\n if (this.#is_tls)\n this.#tls = {\n serverName,\n key,\n cert,\n ca,\n passphrase,\n secureOptions\n };\n else\n this.#tls = null;\n } else\n throw new Error(\"bun-http-polyfill: invalid arguments\");\n if (this.#options = options, callback)\n this.on(\"request\", callback);\n }\n closeAllConnections() {\n const server = this.#server;\n if (!server)\n return;\n this.#server = @undefined, server.stop(!0), this.emit(\"close\");\n }\n closeIdleConnections() {\n }\n close(optionalCallback) {\n const server = this.#server;\n if (!server) {\n if (typeof optionalCallback === \"function\")\n process.nextTick(optionalCallback, new Error(\"Server is not running\"));\n return;\n }\n if (this.#server = @undefined, typeof optionalCallback === \"function\")\n this.once(\"close\", optionalCallback);\n server.stop(), this.emit(\"close\");\n }\n address() {\n if (!this.#server)\n return null;\n const address = this.#server.hostname;\n return {\n address,\n family: isIPv6(address) \? \"IPv6\" : \"IPv4\",\n port: this.#server.port\n };\n }\n listen(port, host, backlog, onListen) {\n const server = this;\n let socketPath;\n if (typeof port == \"string\" && !Number.isSafeInteger(Number(port)))\n socketPath = port;\n if (typeof host === \"function\")\n onListen = host, host = @undefined;\n if (typeof port === \"function\")\n onListen = port;\n else if (typeof port === \"object\") {\n if (port\?.signal\?.addEventListener(\"abort\", () => {\n this.close();\n }), host = port\?.host, port = port\?.port, typeof port\?.callback === \"function\")\n onListen = port\?.callback;\n }\n if (typeof backlog === \"function\")\n onListen = backlog;\n const ResponseClass = this.#options.ServerResponse || ServerResponse, RequestClass = this.#options.IncomingMessage || IncomingMessage;\n try {\n const tls = this.#tls;\n if (tls)\n this.serverName = tls.serverName || host || \"localhost\";\n this.#server = Bun.serve({\n tls,\n port,\n hostname: host,\n unix: socketPath,\n websocket: {\n open(ws) {\n ws.data.open(ws);\n },\n message(ws, message) {\n ws.data.message(ws, message);\n },\n close(ws, code, reason) {\n ws.data.close(ws, code, reason);\n },\n drain(ws) {\n ws.data.drain(ws);\n }\n },\n fetch(req, _server) {\n var pendingResponse, pendingError, rejectFunction, resolveFunction, reject = (err) => {\n if (pendingError)\n return;\n if (pendingError = err, rejectFunction)\n rejectFunction(err);\n }, reply = function(resp) {\n if (pendingResponse)\n return;\n if (pendingResponse = resp, resolveFunction)\n resolveFunction(resp);\n };\n const http_req = new RequestClass(req), http_res = new ResponseClass({ reply, req: http_req });\n if (http_req.once(\"error\", (err) => reject(err)), http_res.once(\"error\", (err) => reject(err)), req.headers.get(\"upgrade\")) {\n const socket = http_req.socket;\n socket[kInternalSocketData] = [_server, http_res, req], server.emit(\"upgrade\", http_req, socket, kEmptyBuffer);\n } else\n server.emit(\"request\", http_req, http_res);\n if (pendingError)\n throw pendingError;\n if (pendingResponse)\n return pendingResponse;\n return new @Promise((resolve, reject2) => {\n resolveFunction = resolve, rejectFunction = reject2;\n });\n }\n }), setTimeout(emitListeningNextTick, 1, this, onListen, null, this.#server.hostname, this.#server.port);\n } catch (err) {\n setTimeout(emitListeningNextTick, 1, this, onListen, err);\n }\n return this;\n }\n setTimeout(msecs, callback) {\n }\n}\nclass IncomingMessage extends Readable {\n method;\n complete;\n constructor(req, defaultIncomingOpts) {\n const method = req.method;\n super();\n const url = new URL(req.url);\n var { type = \"request\", [kInternalRequest]: nodeReq } = defaultIncomingOpts || {};\n this.#noBody = type === \"request\" \? method === \"GET\" || method === \"HEAD\" || method === \"TRACE\" || method === \"CONNECT\" || method === \"OPTIONS\" || (parseInt(req.headers.get(\"Content-Length\") || \"\") || 0) === 0 : !1, this.#req = req, this.method = method, this.#type = type, this.complete = !!this.#noBody, this.#bodyStream = @undefined;\n const socket = new FakeSocket;\n socket.remoteAddress = url.hostname, socket.remotePort = url.port, this.#fakeSocket = socket, this.url = url.pathname + url.search, this.#nodeReq = this.req = nodeReq, assignHeaders(this, req);\n }\n headers;\n rawHeaders;\n _consuming = !1;\n _dumped = !1;\n #bodyStream;\n #fakeSocket;\n #noBody = !1;\n #aborted = !1;\n #req;\n url;\n #type;\n #nodeReq;\n _construct(callback) {\n if (this.#type === \"response\" || this.#noBody) {\n callback();\n return;\n }\n const contentLength = this.#req.headers.get(\"content-length\");\n if ((contentLength \? parseInt(contentLength, 10) : 0) === 0) {\n this.#noBody = !0, callback();\n return;\n }\n callback();\n }\n async#consumeStream(reader) {\n while (!0) {\n var { done, value } = await reader.readMany();\n if (this.#aborted)\n return;\n if (done) {\n this.push(null), this.destroy();\n break;\n }\n for (var v of value)\n this.push(v);\n }\n }\n _read(size) {\n if (this.#noBody)\n this.push(null), this.complete = !0;\n else if (this.#bodyStream == null) {\n const reader = this.#req.body\?.getReader();\n if (!reader) {\n this.push(null);\n return;\n }\n this.#bodyStream = reader, this.#consumeStream(reader);\n }\n }\n get aborted() {\n return this.#aborted;\n }\n #abort() {\n if (this.#aborted)\n return;\n this.#aborted = !0;\n var bodyStream = this.#bodyStream;\n if (!bodyStream)\n return;\n bodyStream.cancel(), this.complete = !0, this.#bodyStream = @undefined, this.push(null);\n }\n get connection() {\n return this.#fakeSocket;\n }\n get statusCode() {\n return this.#req.status;\n }\n get statusMessage() {\n return STATUS_CODES[this.#req.status];\n }\n get httpVersion() {\n return \"1.1\";\n }\n get rawTrailers() {\n return [];\n }\n get httpVersionMajor() {\n return 1;\n }\n get httpVersionMinor() {\n return 1;\n }\n get trailers() {\n return kEmptyObject;\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n}\n\nclass OutgoingMessage extends Writable {\n constructor() {\n super(...arguments);\n }\n #headers;\n headersSent = !1;\n sendDate = !0;\n req;\n timeout;\n #finished = !1;\n [kEndCalled] = !1;\n #fakeSocket;\n #timeoutTimer;\n [kAbortController] = null;\n _implicitHeader() {\n }\n get headers() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n get socket() {\n return this.#fakeSocket \?\?= new FakeSocket;\n }\n set socket(val) {\n this.#fakeSocket = val;\n }\n get connection() {\n return this.socket;\n }\n get finished() {\n return this.#finished;\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n if (!this.#headers)\n return kEmptyObject;\n return this.#headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return headers.set(name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.removeAllListeners(\"timeout\"), this.#timeoutTimer = @undefined;\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar OriginalWriteHeadFn, OriginalImplicitHeadFn;\n\nclass ServerResponse extends Writable {\n constructor(c) {\n super();\n if (!c)\n c = {};\n var req = c.req || {}, reply = c.reply;\n if (this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = @undefined, this.#controller = @undefined, this.#firstWrite = @undefined, this._writableState.decodeStrings = !1, this.#deferred = @undefined, req.method === \"HEAD\")\n this._hasBody = !1;\n }\n req;\n _reply;\n sendDate;\n statusCode;\n #headers;\n headersSent = !1;\n statusMessage;\n #controller;\n #firstWrite;\n _sent100 = !1;\n _defaultKeepAlive = !1;\n _removedConnection = !1;\n _removedContLen = !1;\n _hasBody = !0;\n #deferred = @undefined;\n #finished = !1;\n _implicitHeader() {\n this.writeHead(this.statusCode);\n }\n _write(chunk, encoding, callback) {\n if (!this.#firstWrite && !this.headersSent) {\n this.#firstWrite = chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n controller.write(chunk), callback();\n });\n }\n _writev(chunks, callback) {\n if (chunks.length === 1 && !this.headersSent && !this.#firstWrite) {\n this.#firstWrite = chunks[0].chunk, callback();\n return;\n }\n this.#ensureReadableStreamController((controller) => {\n for (let chunk of chunks)\n controller.write(chunk.chunk);\n callback();\n });\n }\n #ensureReadableStreamController(run) {\n var thisController = this.#controller;\n if (thisController)\n return run(thisController);\n this.headersSent = !0;\n var firstWrite = this.#firstWrite;\n this.#firstWrite = @undefined, this._reply(new Response(new @ReadableStream({\n type: \"direct\",\n pull: (controller) => {\n if (this.#controller = controller, firstWrite)\n controller.write(firstWrite);\n if (firstWrite = @undefined, run(controller), !this.#finished)\n return new @Promise((resolve) => {\n this.#deferred = resolve;\n });\n }\n }), {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n }));\n }\n #drainHeadersIfObservable() {\n if (this._implicitHeader === OriginalImplicitHeadFn && this.writeHead === OriginalWriteHeadFn)\n return;\n this._implicitHeader();\n }\n _final(callback) {\n if (!this.headersSent) {\n var data = this.#firstWrite || \"\";\n this.#firstWrite = @undefined, this.#finished = !0, this.#drainHeadersIfObservable(), this._reply(new Response(data, {\n headers: this.#headers,\n status: this.statusCode,\n statusText: this.statusMessage \?\? STATUS_CODES[this.statusCode]\n })), callback && callback();\n return;\n }\n this.#finished = !0, this.#ensureReadableStreamController((controller) => {\n controller.end(), callback();\n var deferred = this.#deferred;\n if (deferred)\n this.#deferred = @undefined, deferred();\n });\n }\n writeProcessing() {\n throw new Error(\"not implemented\");\n }\n addTrailers(headers) {\n throw new Error(\"not implemented\");\n }\n assignSocket(socket) {\n throw new Error(\"not implemented\");\n }\n detachSocket(socket) {\n throw new Error(\"not implemented\");\n }\n writeContinue(callback) {\n throw new Error(\"not implemented\");\n }\n setTimeout(msecs, callback) {\n throw new Error(\"not implemented\");\n }\n get shouldKeepAlive() {\n return !0;\n }\n get chunkedEncoding() {\n return !1;\n }\n set chunkedEncoding(value) {\n }\n set shouldKeepAlive(value) {\n }\n get useChunkedEncodingByDefault() {\n return !0;\n }\n set useChunkedEncodingByDefault(value) {\n }\n appendHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n headers.append(name, value);\n }\n flushHeaders() {\n }\n getHeader(name) {\n return getHeader(this.#headers, name);\n }\n getHeaders() {\n var headers = this.#headers;\n if (!headers)\n return kEmptyObject;\n return headers.toJSON();\n }\n getHeaderNames() {\n var headers = this.#headers;\n if (!headers)\n return [];\n return @Array.from(headers.keys());\n }\n removeHeader(name) {\n if (!this.#headers)\n return;\n this.#headers.delete(name);\n }\n setHeader(name, value) {\n var headers = this.#headers \?\?= new Headers;\n return setHeader(headers, name, value), this;\n }\n hasHeader(name) {\n if (!this.#headers)\n return !1;\n return this.#headers.has(name);\n }\n writeHead(statusCode, statusMessage, headers) {\n return _writeHead(statusCode, statusMessage, headers, this), this;\n }\n}\nOriginalWriteHeadFn = ServerResponse.prototype.writeHead;\nOriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;\n\nclass ClientRequest extends OutgoingMessage {\n #timeout;\n #res = null;\n #upgradeOrConnect = !1;\n #parser = null;\n #maxHeadersCount = null;\n #reusedSocket = !1;\n #host;\n #protocol;\n #method;\n #port;\n #useDefaultPort;\n #joinDuplicateHeaders;\n #maxHeaderSize;\n #agent = globalAgent;\n #path;\n #socketPath;\n #bodyChunks = null;\n #fetchRequest;\n #signal = null;\n [kAbortController] = null;\n #timeoutTimer = @undefined;\n #options;\n #finished;\n get path() {\n return this.#path;\n }\n get port() {\n return this.#port;\n }\n get method() {\n return this.#method;\n }\n get host() {\n return this.#host;\n }\n get protocol() {\n return this.#protocol;\n }\n _write(chunk, encoding, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = [chunk], callback();\n return;\n }\n this.#bodyChunks.push(chunk), callback();\n }\n _writev(chunks, callback) {\n if (!this.#bodyChunks) {\n this.#bodyChunks = chunks, callback();\n return;\n }\n this.#bodyChunks.push(...chunks), callback();\n }\n _final(callback) {\n if (this.#finished = !0, this[kAbortController] = new AbortController, this[kAbortController].signal.addEventListener(\"abort\", () => {\n this[kClearTimeout]();\n }), this.#signal\?.aborted)\n this[kAbortController].abort();\n var method = this.#method, body = this.#bodyChunks\?.length === 1 \? this.#bodyChunks[0] : @Buffer.concat(this.#bodyChunks || []);\n let url, proxy;\n if (this.#path.startsWith(\"http://\") || this.#path.startsWith(\"https://\"))\n url = this.#path, proxy = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}`;\n else\n url = `${this.#protocol}//${this.#host}${this.#useDefaultPort \? \"\" : \":\" + this.#port}${this.#path}`;\n try {\n this.#fetchRequest = fetch(url, {\n method,\n headers: this.getHeaders(),\n body: body && method !== \"GET\" && method !== \"HEAD\" && method !== \"OPTIONS\" \? body : @undefined,\n redirect: \"manual\",\n verbose: !1,\n signal: this[kAbortController].signal,\n proxy,\n timeout: !1,\n decompress: !1\n }).then((response) => {\n var res = this.#res = new IncomingMessage(response, {\n type: \"response\",\n [kInternalRequest]: this\n });\n this.emit(\"response\", res);\n }).catch((err) => {\n this.emit(\"error\", err);\n }).finally(() => {\n this.#fetchRequest = null, this[kClearTimeout]();\n });\n } catch (err) {\n this.emit(\"error\", err);\n } finally {\n callback();\n }\n }\n get aborted() {\n return this.#signal\?.aborted || !!this[kAbortController]\?.signal.aborted;\n }\n abort() {\n if (this.aborted)\n return;\n this[kAbortController].abort();\n }\n constructor(input, options, cb) {\n super();\n if (typeof input === \"string\") {\n const urlStr = input;\n try {\n var urlObject = new URL(urlStr);\n } catch (e) {\n @throwTypeError(`Invalid URL: ${urlStr}`);\n }\n input = urlToHttpOptions(urlObject);\n } else if (input && typeof input === \"object\" && input instanceof URL)\n input = urlToHttpOptions(input);\n else\n cb = options, options = input, input = null;\n if (typeof options === \"function\")\n cb = options, options = input || kEmptyObject;\n else\n options = ObjectAssign(input || {}, options);\n var defaultAgent = options._defaultAgent || Agent.globalAgent;\n let protocol = options.protocol;\n if (!protocol)\n if (options.port === 443)\n protocol = \"https:\";\n else\n protocol = defaultAgent.protocol || \"http:\";\n switch (this.#protocol = protocol, this.#agent\?.protocol) {\n case @undefined:\n break;\n case \"http:\":\n if (protocol === \"https:\") {\n defaultAgent = this.#agent = getDefaultHTTPSAgent();\n break;\n }\n case \"https:\":\n if (protocol === \"https\") {\n defaultAgent = this.#agent = Agent.globalAgent;\n break;\n }\n default:\n break;\n }\n if (options.path) {\n const path = @String(options.path);\n if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null)\n throw new Error(\"Path contains unescaped characters\");\n }\n if (protocol !== \"http:\" && protocol !== \"https:\" && protocol) {\n const expectedProtocol = defaultAgent\?.protocol \?\? \"http:\";\n throw new Error(`Protocol mismatch. Expected: ${expectedProtocol}. Got: ${protocol}`);\n }\n const defaultPort = protocol === \"https:\" \? 443 : 80;\n this.#port = options.port || options.defaultPort || this.#agent\?.defaultPort || defaultPort, this.#useDefaultPort = this.#port === defaultPort;\n const host = this.#host = options.host = validateHost(options.hostname, \"hostname\") || validateHost(options.host, \"host\") || \"localhost\";\n this.#socketPath = options.socketPath;\n const signal = options.signal;\n if (signal)\n signal.addEventListener(\"abort\", () => {\n this[kAbortController]\?.abort();\n }), this.#signal = signal;\n let method = options.method;\n const methodIsString = typeof method === \"string\";\n if (method !== null && method !== @undefined && !methodIsString)\n throw new Error(\"ERR_INVALID_ARG_TYPE: options.method\");\n if (methodIsString && method) {\n if (!checkIsHttpToken(method))\n throw new Error(\"ERR_INVALID_HTTP_TOKEN: Method\");\n method = this.#method = StringPrototypeToUpperCase.call(method);\n } else\n method = this.#method = \"GET\";\n const _maxHeaderSize = options.maxHeaderSize;\n this.#maxHeaderSize = _maxHeaderSize;\n var _joinDuplicateHeaders = options.joinDuplicateHeaders;\n if (this.#joinDuplicateHeaders = _joinDuplicateHeaders, this.#path = options.path || \"/\", cb)\n this.once(\"response\", cb);\n this.#finished = !1, this.#res = null, this.#upgradeOrConnect = !1, this.#parser = null, this.#maxHeadersCount = null, this.#reusedSocket = !1, this.#host = host, this.#protocol = protocol;\n var timeout = options.timeout;\n if (timeout !== @undefined && timeout !== 0)\n this.setTimeout(timeout, @undefined);\n if (!ArrayIsArray(headers)) {\n var headers = options.headers;\n if (headers)\n for (let key in headers)\n this.setHeader(key, headers[key]);\n var auth = options.auth;\n if (auth && !this.getHeader(\"Authorization\"))\n this.setHeader(\"Authorization\", \"Basic \" + @Buffer.from(auth).toString(\"base64\"));\n }\n var { signal: _signal, ...optsWithoutSignal } = options;\n this.#options = optsWithoutSignal;\n }\n setSocketKeepAlive(enable = !0, initialDelay = 0) {\n }\n setNoDelay(noDelay = !0) {\n }\n [kClearTimeout]() {\n if (this.#timeoutTimer)\n clearTimeout(this.#timeoutTimer), this.#timeoutTimer = @undefined, this.removeAllListeners(\"timeout\");\n }\n #onTimeout() {\n this.#timeoutTimer = @undefined, this[kAbortController]\?.abort(), this.emit(\"timeout\");\n }\n setTimeout(msecs, callback) {\n if (this.destroyed)\n return this;\n if (this.timeout = msecs = validateMsecs(msecs, \"msecs\"), clearTimeout(this.#timeoutTimer), msecs === 0) {\n if (callback !== @undefined)\n validateFunction(callback, \"callback\"), this.removeListener(\"timeout\", callback);\n this.#timeoutTimer = @undefined;\n } else if (this.#timeoutTimer = setTimeout(this.#onTimeout.bind(this), msecs).unref(), callback !== @undefined)\n validateFunction(callback, \"callback\"), this.once(\"timeout\", callback);\n return this;\n }\n}\nvar tokenRegExp = /^[\\^_`a-zA-Z\\-0-9!#$%&'*+.|~]+$/, METHODS = [\n \"ACL\",\n \"BIND\",\n \"CHECKOUT\",\n \"CONNECT\",\n \"COPY\",\n \"DELETE\",\n \"GET\",\n \"HEAD\",\n \"LINK\",\n \"LOCK\",\n \"M-SEARCH\",\n \"MERGE\",\n \"MKACTIVITY\",\n \"MKCALENDAR\",\n \"MKCOL\",\n \"MOVE\",\n \"NOTIFY\",\n \"OPTIONS\",\n \"PATCH\",\n \"POST\",\n \"PROPFIND\",\n \"PROPPATCH\",\n \"PURGE\",\n \"PUT\",\n \"REBIND\",\n \"REPORT\",\n \"SEARCH\",\n \"SOURCE\",\n \"SUBSCRIBE\",\n \"TRACE\",\n \"UNBIND\",\n \"UNLINK\",\n \"UNLOCK\",\n \"UNSUBSCRIBE\"\n], STATUS_CODES = {\n 100: \"Continue\",\n 101: \"Switching Protocols\",\n 102: \"Processing\",\n 103: \"Early Hints\",\n 200: \"OK\",\n 201: \"Created\",\n 202: \"Accepted\",\n 203: \"Non-Authoritative Information\",\n 204: \"No Content\",\n 205: \"Reset Content\",\n 206: \"Partial Content\",\n 207: \"Multi-Status\",\n 208: \"Already Reported\",\n 226: \"IM Used\",\n 300: \"Multiple Choices\",\n 301: \"Moved Permanently\",\n 302: \"Found\",\n 303: \"See Other\",\n 304: \"Not Modified\",\n 305: \"Use Proxy\",\n 307: \"Temporary Redirect\",\n 308: \"Permanent Redirect\",\n 400: \"Bad Request\",\n 401: \"Unauthorized\",\n 402: \"Payment Required\",\n 403: \"Forbidden\",\n 404: \"Not Found\",\n 405: \"Method Not Allowed\",\n 406: \"Not Acceptable\",\n 407: \"Proxy Authentication Required\",\n 408: \"Request Timeout\",\n 409: \"Conflict\",\n 410: \"Gone\",\n 411: \"Length Required\",\n 412: \"Precondition Failed\",\n 413: \"Payload Too Large\",\n 414: \"URI Too Long\",\n 415: \"Unsupported Media Type\",\n 416: \"Range Not Satisfiable\",\n 417: \"Expectation Failed\",\n 418: \"I'm a Teapot\",\n 421: \"Misdirected Request\",\n 422: \"Unprocessable Entity\",\n 423: \"Locked\",\n 424: \"Failed Dependency\",\n 425: \"Too Early\",\n 426: \"Upgrade Required\",\n 428: \"Precondition Required\",\n 429: \"Too Many Requests\",\n 431: \"Request Header Fields Too Large\",\n 451: \"Unavailable For Legal Reasons\",\n 500: \"Internal Server Error\",\n 501: \"Not Implemented\",\n 502: \"Bad Gateway\",\n 503: \"Service Unavailable\",\n 504: \"Gateway Timeout\",\n 505: \"HTTP Version Not Supported\",\n 506: \"Variant Also Negotiates\",\n 507: \"Insufficient Storage\",\n 508: \"Loop Detected\",\n 509: \"Bandwidth Limit Exceeded\",\n 510: \"Not Extended\",\n 511: \"Network Authentication Required\"\n}, globalAgent = new Agent;\n$ = {\n Agent,\n Server,\n METHODS,\n STATUS_CODES,\n createServer,\n ServerResponse,\n IncomingMessage,\n request,\n get,\n maxHeaderSize: 16384,\n validateHeaderName,\n validateHeaderValue,\n setMaxIdleHTTPParsers(max) {\n },\n globalAgent,\n ClientRequest,\n OutgoingMessage\n};\nreturn $})\n"_s; // // diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts index b8302c1d88de7f..24c0b40bf93502 100644 --- a/test/js/node/http/node-http.test.ts +++ b/test/js/node/http/node-http.test.ts @@ -8,6 +8,7 @@ import { Server, validateHeaderName, validateHeaderValue, + ServerResponse, } from "node:http"; import { createTest } from "node-harness"; import url from "node:url"; @@ -113,6 +114,23 @@ describe("node:http", () => { }); }); + describe("response", () => { + test("set-cookie works with getHeader", () => { + const res = new ServerResponse({}); + res.setHeader("Set-Cookie", ["swag=true", "yolo=true"]); + expect(res.getHeader("Set-Cookie")).toEqual(["swag=true", "yolo=true"]); + }); + test("set-cookie works with getHeaders", () => { + const res = new ServerResponse({}); + res.setHeader("Set-Cookie", ["swag=true", "yolo=true"]); + res.setHeader("test", "test"); + expect(res.getHeaders()).toEqual({ + "Set-Cookie": ["swag=true", "yolo=true"], + "test": "test", + }); + }); + }); + describe("request", () => { function runTest(done: Function, callback: (server: Server, port: number, done: (err?: Error) => void) => void) { var timer;