Files
aitbc/dev/env/node_modules/ethers/src.ts/utils/geturl.ts
aitbc 816e258d4c refactor: move brother_node development artifact to dev/test-nodes subdirectory
Development Artifact Cleanup:
 BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location
- dev/test-nodes/brother_node/: Moved from root directory for better organization
- Contains development configuration, test logs, and test chain data
- No impact on production systems - purely development/testing artifact

 DEVELOPMENT ARTIFACTS IDENTIFIED:
- Chain ID: aitbc-brother-chain (test/development chain)
- Ports: 8010 (P2P) and 8011 (RPC) - different from production
- Environment: .env file with test configuration
- Logs: rpc.log and node.log from development testing session (March 15, 2026)

 ROOT DIRECTORY CLEANUP: Removed development clutter from production directory
- brother_node/ moved to dev/test-nodes/brother_node/
- Root directory now contains only production-ready components
- Development artifacts properly organized in dev/ subdirectory

DIRECTORY STRUCTURE IMPROVEMENT:
📁 dev/test-nodes/: Development and testing node configurations
🏗️ Root Directory: Clean production structure with only essential components
🧪 Development Isolation: Test environments separated from production

BENEFITS:
 Clean Production Directory: No development artifacts in root
 Better Organization: Development nodes grouped in dev/ subdirectory
 Clear Separation: Production vs development environments clearly distinguished
 Maintainability: Easier to identify and manage development components

RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
2026-03-30 17:09:06 +02:00

142 lines
4.8 KiB
TypeScript
Executable File

import http from "http";
import https from "https";
import { gunzipSync } from "zlib";
import { assert, makeError } from "./errors.js";
import { getBytes } from "./data.js";
import type {
FetchGetUrlFunc, FetchRequest, FetchCancelSignal, GetUrlResponse
} from "./fetch.js";
/**
* @_ignore:
*/
export function createGetUrl(options?: Record<string, any>): FetchGetUrlFunc {
async function getUrl(req: FetchRequest, signal?: FetchCancelSignal): Promise<GetUrlResponse> {
// Make sure we weren't cancelled before sending
assert(signal == null || !signal.cancelled, "request cancelled before sending", "CANCELLED");
const protocol = req.url.split(":")[0].toLowerCase();
assert(protocol === "http" || protocol === "https", `unsupported protocol ${ protocol }`, "UNSUPPORTED_OPERATION", {
info: { protocol },
operation: "request"
});
assert(protocol === "https" || !req.credentials || req.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", {
operation: "request"
});
const method = req.method;
const headers = Object.assign({ }, req.headers);
const reqOptions: any = { method, headers };
if (options) {
if (options.agent) { reqOptions.agent = options.agent; }
}
// Create a Node-specific AbortController, if available
let abort: null | AbortController = null;
try {
abort = new AbortController();
reqOptions.abort = abort.signal;
} catch (e) { console.log(e); }
const request = ((protocol === "http") ? http: https).request(req.url, reqOptions);
request.setTimeout(req.timeout);
const body = req.body;
if (body) { request.write(Buffer.from(body)); }
request.end();
return new Promise((resolve, reject) => {
if (signal) {
signal.addListener(() => {
if (abort) { abort.abort(); }
reject(makeError("request cancelled", "CANCELLED"));
});
}
request.on("timeout", () => {
reject(makeError("request timeout", "TIMEOUT"));
});
request.once("response", (resp: http.IncomingMessage) => {
const statusCode = resp.statusCode || 0;
const statusMessage = resp.statusMessage || "";
const headers = Object.keys(resp.headers || {}).reduce((accum, name) => {
let value = resp.headers[name] || "";
if (Array.isArray(value)) {
value = value.join(", ");
}
accum[name] = value;
return accum;
}, <{ [ name: string ]: string }>{ });
let body: null | Uint8Array = null;
//resp.setEncoding("utf8");
resp.on("data", (chunk: Uint8Array) => {
if (signal) {
try {
signal.checkSignal();
} catch (error) {
return reject(error);
}
}
if (body == null) {
body = chunk;
} else {
const newBody = new Uint8Array(body.length + chunk.length);
newBody.set(body, 0);
newBody.set(chunk, body.length);
body = newBody;
}
});
resp.on("end", () => {
try {
if (headers["content-encoding"] === "gzip" && body) {
body = getBytes(gunzipSync(body));
}
resolve({ statusCode, statusMessage, headers, body });
} catch (error) {
reject(makeError("bad response data", "SERVER_ERROR", {
request: req, info: { response: resp, error }
}));
}
});
resp.on("error", (error) => {
//@TODO: Should this just return nornal response with a server error?
(<any>error).response = { statusCode, statusMessage, headers, body };
reject(error);
});
});
request.on("error", (error) => { reject(error); });
});
}
return getUrl;
}
// @TODO: remove in v7; provided for backwards compat
const defaultGetUrl: FetchGetUrlFunc = createGetUrl({ });
/**
* @_ignore:
*/
export async function getUrl(req: FetchRequest, signal?: FetchCancelSignal): Promise<GetUrlResponse> {
return defaultGetUrl(req, signal);
}