Files
2026-02-10 01:14:19 +00:00

40 lines
2.2 KiB
JavaScript

import { t as IS_PATCHED_MODULE } from "./glossary-glQBRnVD.mjs";
import { c as InterceptorReadyState, i as RequestController, l as deleteGlobalSymbol, o as INTERNAL_REQUEST_ID_HEADER_NAME, r as createRequestId, s as Interceptor, t as FetchResponse, u as getGlobalSymbol } from "./fetchUtils-CoU35g3M.mjs";
import { t as BatchInterceptor } from "./BatchInterceptor-DFaBPilf.mjs";
import { n as encodeBuffer, t as decodeBuffer } from "./bufferUtils-_8XfKIfX.mjs";
import { t as getRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
//#region src/utils/getCleanUrl.ts
/**
* Removes query parameters and hashes from a given URL.
*/
function getCleanUrl(url, isAbsolute = true) {
return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
}
//#endregion
//#region src/utils/resolveWebSocketUrl.ts
/**
* Resolve potentially relative WebSocket URLs the same way
* the browser does (replace the protocol, use the origin, etc).
*
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
*/
function resolveWebSocketUrl(url) {
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
if (url.protocol === "http:") url.protocol = "ws:";
else if (url.protocol === "https:") url.protocol = "wss:";
if (url.protocol !== "ws:" && url.protocol !== "wss:")
/**
* @note These errors are modeled after the browser errors.
* The exact error messages aren't provided in the specification.
* Node.js uses more obscure error messages that I don't wish to replicate.
*/
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
if (url.hash !== "") throw new SyntaxError(`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`);
return url.href;
}
//#endregion
export { BatchInterceptor, FetchResponse, INTERNAL_REQUEST_ID_HEADER_NAME, IS_PATCHED_MODULE, Interceptor, InterceptorReadyState, RequestController, createRequestId, decodeBuffer, deleteGlobalSymbol, encodeBuffer, getCleanUrl, getGlobalSymbol, getRawRequest, resolveWebSocketUrl };
//# sourceMappingURL=index.mjs.map