diff --git a/README.md b/README.md index d81e5d7..572ea12 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ the tests subdirectory. #### Setup a basic stand-alone proxy server ```js -import * as http from "http"; +import * as http from "node:http"; import { createProxyServer } from "http-proxy-3"; // Create your proxy server and set the target in the options. @@ -192,7 +192,7 @@ This example shows how you can proxy a request using your own HTTP server and also you can put your own logic to handle the request. ```js -import * as http from "http"; +import * as http from "node:http"; import { createProxyServer } from "http-proxy-3"; // Create a proxy server with custom application logic @@ -219,7 +219,7 @@ This example shows how you can proxy a request using your own HTTP server that modifies the outgoing proxy request by adding a special header. ```js -import * as http from "http"; +import * as http from "node:http"; import { createProxyServer } from "http-proxy-3"; // Create a proxy server with custom application logic @@ -261,7 +261,7 @@ Sometimes when you have received a HTML/XML document from the server of origin y #### Setup a stand-alone proxy server with latency ```js -import * as http from "http"; +import * as http from "node:http"; import { createProxyServer } from "http-proxy-3"; // Create a proxy server with latency @@ -372,7 +372,7 @@ httpProxy Also you can proxy the websocket requests just calling the `ws(req, socket, head)` method. ```js -import * as http from "http"; +import * as http from "node:http"; import { createProxyServer } from "http-proxy-3"; // Setup our server to proxy standard HTTP requests diff --git a/lib/http-proxy/common.ts b/lib/http-proxy/common.ts index 5ae4f62..47a5478 100644 --- a/lib/http-proxy/common.ts +++ b/lib/http-proxy/common.ts @@ -1,8 +1,8 @@ import type { NormalizedServerOptions, ProxyTargetDetailed, ServerOptions } from "./index"; -import { type IncomingMessage as Request } from "http"; -import { TLSSocket } from "tls"; -import type { Socket } from "net"; -import * as urllib from "url"; +import { type IncomingMessage as Request } from "node:http"; +import { TLSSocket } from "node:tls"; +import type { Socket } from "node:net"; +import * as urllib from "node:url"; const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i; @@ -149,16 +149,16 @@ export function setupSocket(socket: Socket): Socket { export function getPort( // Incoming HTTP request. req: Request, -): // Retjurn the port number, as a string. -string { + // Return the port number, as a string. +): string { const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : ""; return res ? res[1] : hasEncryptedConnection(req) ? "443" : "80"; } // Check if the request has an encrypted connection. export function hasEncryptedConnection( - req: // Incoming HTTP request. - Request, + // Incoming HTTP request. + req: Request, ): boolean { const conn = req.connection; return ( diff --git a/lib/http-proxy/index.ts b/lib/http-proxy/index.ts index 8d43984..75fa5ee 100644 --- a/lib/http-proxy/index.ts +++ b/lib/http-proxy/index.ts @@ -1,10 +1,10 @@ -import * as http from "http"; -import * as https from "https"; -import * as net from "net"; +import * as http from "node:http"; +import * as https from "node:https"; +import * as net from "node:net"; import { WEB_PASSES } from "./passes/web-incoming"; import { WS_PASSES } from "./passes/ws-incoming"; -import { EventEmitter } from "events"; -import type { Stream } from "stream"; +import { EventEmitter } from "node:events"; +import type { Stream } from "node:stream"; import debug from "debug"; import { toURL } from "./common"; diff --git a/lib/http-proxy/passes/web-incoming.ts b/lib/http-proxy/passes/web-incoming.ts index 5415a6d..dd8cc81 100644 --- a/lib/http-proxy/passes/web-incoming.ts +++ b/lib/http-proxy/passes/web-incoming.ts @@ -7,16 +7,16 @@ The names of passes are exported as WEB_PASSES from this module. */ -import * as http from "http"; -import * as https from "https"; +import * as http from "node:http"; +import * as https from "node:https"; import { OUTGOING_PASSES } from "./web-outgoing"; import * as common from "../common"; import * as followRedirects from "follow-redirects"; import { type IncomingMessage as Request, type ServerResponse as Response, -} from "http"; -import { type Socket } from "net"; +} from "node:http"; +import { type Socket } from "node:net"; import type { ErrorCallback, NormalizedServerOptions, NormalizeProxyTarget, ProxyServer, ProxyTarget, ProxyTargetUrl, ServerOptions } from ".."; export type ProxyResponse = Request & { diff --git a/lib/http-proxy/passes/ws-incoming.ts b/lib/http-proxy/passes/ws-incoming.ts index 2397860..fd99fa4 100644 --- a/lib/http-proxy/passes/ws-incoming.ts +++ b/lib/http-proxy/passes/ws-incoming.ts @@ -8,11 +8,11 @@ flexible. The names of passes are exported as WS_PASSES from this module. */ -import * as http from "http"; -import * as https from "https"; +import * as http from "node:http"; +import * as https from "node:https"; import * as common from "../common"; import type { Request } from "./web-incoming"; -import type { Socket } from "net"; +import type { Socket } from "node:net"; import debug from "debug"; import type { NormalizedServerOptions, ProxyServer } from ".."; diff --git a/lib/test/balancer/simple-balancer-with-websockets.test.ts b/lib/test/balancer/simple-balancer-with-websockets.test.ts index d8d7bbc..4bccebd 100644 --- a/lib/test/balancer/simple-balancer-with-websockets.test.ts +++ b/lib/test/balancer/simple-balancer-with-websockets.test.ts @@ -4,10 +4,10 @@ Simple round robin load balancer for websockets pnpm test ./simple-balancer-with-websockets.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; -import { once } from "events"; +import { once } from "node:events"; import fetch from "node-fetch"; describe("A simple round-robin load balancer that supports websockets", () => { diff --git a/lib/test/balancer/simple-balancer.test.ts b/lib/test/balancer/simple-balancer.test.ts index e17bc3e..27b771c 100644 --- a/lib/test/balancer/simple-balancer.test.ts +++ b/lib/test/balancer/simple-balancer.test.ts @@ -4,7 +4,7 @@ simple-balancer.test.ts: Example of a simple round robin HTTP load balancer pnpm test simple-balancer.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; import fetch from "node-fetch"; diff --git a/lib/test/get-port.ts b/lib/test/get-port.ts index 31e8c1d..b775736 100644 --- a/lib/test/get-port.ts +++ b/lib/test/get-port.ts @@ -1,4 +1,4 @@ -import { createServer } from "http"; +import { createServer } from "node:http"; export default async function getPort(): Promise { return new Promise((resolve, reject) => { @@ -14,4 +14,4 @@ export default async function getPort(): Promise { }); server.on("error", reject); }); -} \ No newline at end of file +} diff --git a/lib/test/http/basic-proxy.test.ts b/lib/test/http/basic-proxy.test.ts index 44b929a..51b4070 100644 --- a/lib/test/http/basic-proxy.test.ts +++ b/lib/test/http/basic-proxy.test.ts @@ -6,7 +6,7 @@ DEVELOPMENT: pnpm test basic-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import log from "../log"; import getPort from "../get-port"; diff --git a/lib/test/http/custom-proxy-error.test.ts b/lib/test/http/custom-proxy-error.test.ts index a44d492..8d28a09 100644 --- a/lib/test/http/custom-proxy-error.test.ts +++ b/lib/test/http/custom-proxy-error.test.ts @@ -5,7 +5,7 @@ pnpm test ./custom-proxy-error.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import fetch from "node-fetch"; diff --git a/lib/test/http/double-slashes.test.ts b/lib/test/http/double-slashes.test.ts index 7ef9830..71089fb 100644 --- a/lib/test/http/double-slashes.test.ts +++ b/lib/test/http/double-slashes.test.ts @@ -1,7 +1,7 @@ import express from "express"; import getPort from "../get-port"; import ProxyServer, { createServer } from "../.."; -import http from "http"; +import http from "node:http"; // See https://github.com/sagemathinc/http-proxy-3/issues/6 diff --git a/lib/test/http/error-handling.test.ts b/lib/test/http/error-handling.test.ts index 4e02a8c..2fbf969 100644 --- a/lib/test/http/error-handling.test.ts +++ b/lib/test/http/error-handling.test.ts @@ -3,7 +3,7 @@ */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import log from "../log"; import fetch from "node-fetch"; diff --git a/lib/test/http/forward-and-target-proxy.test.ts b/lib/test/http/forward-and-target-proxy.test.ts index 4731abd..a16c807 100644 --- a/lib/test/http/forward-and-target-proxy.test.ts +++ b/lib/test/http/forward-and-target-proxy.test.ts @@ -7,7 +7,7 @@ pnpm test forward-and-target-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import log from "../log"; import getPort from "../get-port"; diff --git a/lib/test/http/forward-proxy.test.ts b/lib/test/http/forward-proxy.test.ts index 0e10af3..8478d69 100644 --- a/lib/test/http/forward-proxy.test.ts +++ b/lib/test/http/forward-proxy.test.ts @@ -9,7 +9,7 @@ DEVELOPMENT: pnpm test forward-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import log from "../log"; import getPort from "../get-port"; diff --git a/lib/test/http/latent-proxy.test.ts b/lib/test/http/latent-proxy.test.ts index d138d2d..5114a2a 100644 --- a/lib/test/http/latent-proxy.test.ts +++ b/lib/test/http/latent-proxy.test.ts @@ -2,7 +2,7 @@ pnpm test latent-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; diff --git a/lib/test/http/proxy-http-to-https.test.ts b/lib/test/http/proxy-http-to-https.test.ts index b26148e..bfa7a2f 100644 --- a/lib/test/http/proxy-http-to-https.test.ts +++ b/lib/test/http/proxy-http-to-https.test.ts @@ -4,7 +4,7 @@ pnpm test proxy-http-to-https.test.ts We proxy https://google.com via a local non-https http server. */ -import * as https from "https"; +import * as https from "node:https"; import * as httpProxy from "../.."; import getPort from "../get-port"; import fetch from "node-fetch"; diff --git a/lib/test/http/proxy-https-to-http.test.ts b/lib/test/http/proxy-https-to-http.test.ts index 646c7bb..bec2751 100644 --- a/lib/test/http/proxy-https-to-http.test.ts +++ b/lib/test/http/proxy-https-to-http.test.ts @@ -2,11 +2,11 @@ pnpm test proxy-https-to-http.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; -import { join } from "path"; -import { readFile } from "fs/promises"; +import { join } from "node:path"; +import { readFile } from "node:fs/promises"; import fetch from "node-fetch"; const fixturesDir = join(__dirname, "..", "fixtures"); diff --git a/lib/test/http/proxy-https-to-https.test.ts b/lib/test/http/proxy-https-to-https.test.ts index ed011b4..dd179a8 100644 --- a/lib/test/http/proxy-https-to-https.test.ts +++ b/lib/test/http/proxy-https-to-https.test.ts @@ -3,11 +3,11 @@ pnpm test proxy-https-to-https.test.ts */ -import * as https from "https"; +import * as https from "node:https"; import * as httpProxy from "../.."; import getPort from "../get-port"; -import { join } from "path"; -import { readFile } from "fs/promises"; +import { join } from "node:path"; +import { readFile } from "node:fs/promises"; import fetch from "node-fetch"; const fixturesDir = join(__dirname, "..", "fixtures"); diff --git a/lib/test/http/reverse-proxy.test.ts b/lib/test/http/reverse-proxy.test.ts index 2215ef5..06f5f7b 100644 --- a/lib/test/http/reverse-proxy.test.ts +++ b/lib/test/http/reverse-proxy.test.ts @@ -4,10 +4,10 @@ reverse-proxy.test.ts: Example of reverse proxying (with HTTPS support) pnpm test ./reverse-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; -import * as net from "net"; +import * as net from "node:net"; import log from "../log"; import { HttpsProxyAgent } from "https-proxy-agent"; import fetch from "node-fetch"; diff --git a/lib/test/http/server-sent-events.test.ts b/lib/test/http/server-sent-events.test.ts index cab24b4..ba0f685 100644 --- a/lib/test/http/server-sent-events.test.ts +++ b/lib/test/http/server-sent-events.test.ts @@ -5,7 +5,7 @@ pnpm test ./server-sent-events.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import { createSession } from "better-sse"; import { EventSource } from "eventsource"; diff --git a/lib/test/lib/http-proxy-passes-web-incoming.test.ts b/lib/test/lib/http-proxy-passes-web-incoming.test.ts index 7fc59fc..e1592bd 100644 --- a/lib/test/lib/http-proxy-passes-web-incoming.test.ts +++ b/lib/test/lib/http-proxy-passes-web-incoming.test.ts @@ -8,7 +8,7 @@ import { XHeaders, } from "../../http-proxy/passes/web-incoming"; import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import concat from "concat-stream"; import * as async from "async"; import getPort from "../get-port"; diff --git a/lib/test/lib/http-proxy-passes-web-outgoing.test.ts b/lib/test/lib/http-proxy-passes-web-outgoing.test.ts index 8497619..c953534 100644 --- a/lib/test/lib/http-proxy-passes-web-outgoing.test.ts +++ b/lib/test/lib/http-proxy-passes-web-outgoing.test.ts @@ -6,7 +6,7 @@ import { writeHeaders as writeHeaders0, } from "../../http-proxy/passes/web-outgoing"; import * as url from "url"; -import http from "http"; +import http from "node:http"; const state: any = { headers: {} }; diff --git a/lib/test/lib/http-proxy.test.ts b/lib/test/lib/http-proxy.test.ts index 4b73a35..5af3cb2 100644 --- a/lib/test/lib/http-proxy.test.ts +++ b/lib/test/lib/http-proxy.test.ts @@ -5,14 +5,14 @@ pnpm test ./http-proxy.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; -import * as net from "net"; +import * as net from "node:net"; import WebSocket, { WebSocketServer } from "ws"; import { Server } from "socket.io"; import { io as socketioClient } from "socket.io-client"; import wait from "../wait"; -import { once } from "events"; +import { once } from "node:events"; const ports: { [port: string]: number } = {}; let portIndex = -1; diff --git a/lib/test/lib/https-proxy.test.ts b/lib/test/lib/https-proxy.test.ts index 786f344..718d5af 100644 --- a/lib/test/lib/https-proxy.test.ts +++ b/lib/test/lib/https-proxy.test.ts @@ -1,9 +1,9 @@ import * as httpProxy from "../.."; -import * as http from "http"; -import * as https from "https"; +import * as http from "node:http"; +import * as https from "node:https"; import getPort from "../get-port"; -import { join } from "path"; -import { readFileSync } from "fs"; +import { join } from "node:path"; +import { readFileSync } from "node:fs"; const ports: { [port: string]: number } = {}; let portIndex = -1; diff --git a/lib/test/middleware/body-decoder-middleware.test.ts b/lib/test/middleware/body-decoder-middleware.test.ts index 572fe53..b1ffd6e 100644 --- a/lib/test/middleware/body-decoder-middleware.test.ts +++ b/lib/test/middleware/body-decoder-middleware.test.ts @@ -5,7 +5,7 @@ pnpm test body-decoder-middleware.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import connect from "connect"; import bodyParser from "body-parser"; diff --git a/lib/test/middleware/gzip-middleware.test.ts b/lib/test/middleware/gzip-middleware.test.ts index c2041dc..3369523 100644 --- a/lib/test/middleware/gzip-middleware.test.ts +++ b/lib/test/middleware/gzip-middleware.test.ts @@ -5,7 +5,7 @@ pnpm test ./gzip-middleware.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import connect from "connect"; import compression from "compression"; diff --git a/lib/test/middleware/modify-response-middleware.test.ts b/lib/test/middleware/modify-response-middleware.test.ts index e73c9a0..cd0d54f 100644 --- a/lib/test/middleware/modify-response-middleware.test.ts +++ b/lib/test/middleware/modify-response-middleware.test.ts @@ -5,7 +5,7 @@ pnpm test modify-response-middleware.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; import connect, { type NextFunction } from "connect"; import fetch from "node-fetch"; diff --git a/lib/test/security/blacklist-headers.test.ts b/lib/test/security/blacklist-headers.test.ts index 7b8e734..3cbf8b4 100644 --- a/lib/test/security/blacklist-headers.test.ts +++ b/lib/test/security/blacklist-headers.test.ts @@ -5,7 +5,7 @@ pnpm test ./blacklist-headers.test.ts */ import * as httpProxy from "../.."; -import * as http from "http"; +import * as http from "node:http"; import getPort from "../get-port"; describe("blacklisting the Trailer header", () => { diff --git a/lib/test/websocket/latent-websocket-proxy.test.ts b/lib/test/websocket/latent-websocket-proxy.test.ts index 2b9eb6f..a963b08 100644 --- a/lib/test/websocket/latent-websocket-proxy.test.ts +++ b/lib/test/websocket/latent-websocket-proxy.test.ts @@ -6,8 +6,8 @@ pnpm test latent-websocket-proxy.test.ts import * as httpProxy from "../.."; import getPort from "../get-port"; -import { once } from "events"; -import http, { createServer } from "http"; +import { once } from "node:events"; +import http, { createServer } from "node:http"; import { Server } from "socket.io"; import { io as socketioClient } from "socket.io-client"; diff --git a/lib/test/websocket/simple-websocket-proxy.test.ts b/lib/test/websocket/simple-websocket-proxy.test.ts index 810302d..6379e20 100644 --- a/lib/test/websocket/simple-websocket-proxy.test.ts +++ b/lib/test/websocket/simple-websocket-proxy.test.ts @@ -11,11 +11,11 @@ DEVELOPMENT: pnpm test simple-websocket-proxy.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import log from "../log"; import getPort from "../get-port"; -import { once } from "events"; +import { once } from "node:events"; describe("Example of simple proxying of a WebSocket", () => { let ports: Record<'ws' | 'proxy', number>; diff --git a/lib/test/websocket/standalone-websocket-proxy.test.ts b/lib/test/websocket/standalone-websocket-proxy.test.ts index 6ac13ce..43106a4 100644 --- a/lib/test/websocket/standalone-websocket-proxy.test.ts +++ b/lib/test/websocket/standalone-websocket-proxy.test.ts @@ -6,8 +6,8 @@ pnpm test ./standalone-websocket-proxy.test.ts import * as httpProxy from "../.."; import getPort from "../get-port"; -import { once } from "events"; -import http, { createServer } from "http"; +import { once } from "node:events"; +import http, { createServer } from "node:http"; import { Server } from "socket.io"; import { io as socketioClient } from "socket.io-client"; diff --git a/lib/test/websocket/websocket-load.test.ts b/lib/test/websocket/websocket-load.test.ts index b329348..c7a4441 100644 --- a/lib/test/websocket/websocket-load.test.ts +++ b/lib/test/websocket/websocket-load.test.ts @@ -4,11 +4,11 @@ pnpm test websocket-load.test.ts */ -import * as http from "http"; +import * as http from "node:http"; import * as httpProxy from "../.."; import getPort from "../get-port"; import wait from "../wait"; -import { once } from "events"; +import { once } from "node:events"; describe("Load testing proxying a WebSocket", () => { let ports: Record<'ws' | 'proxy', number>; diff --git a/lib/test/websocket/websocket-proxy-websocket.test.ts b/lib/test/websocket/websocket-proxy-websocket.test.ts index 5308e68..957efcb 100644 --- a/lib/test/websocket/websocket-proxy-websocket.test.ts +++ b/lib/test/websocket/websocket-proxy-websocket.test.ts @@ -17,7 +17,7 @@ import * as httpProxy from "../.."; import getPort from "../get-port"; import { Server } from "socket.io"; import { io as socketioClient } from "socket.io-client"; -import { once } from "events"; +import { once } from "node:events"; describe("Multilevel Proxying of a Websocket using Socket.io", () => { let ports: Record<'socketio' | 'inner' | 'outer', number>; diff --git a/lib/test/websocket/websocket-proxy.test.ts b/lib/test/websocket/websocket-proxy.test.ts index 24616ba..d6774b8 100644 --- a/lib/test/websocket/websocket-proxy.test.ts +++ b/lib/test/websocket/websocket-proxy.test.ts @@ -14,8 +14,8 @@ import * as httpProxy from "../.."; import log from "../log"; import getPort from "../get-port"; import wait from "../wait"; -import { once } from "events"; -import { createServer } from "http"; +import { once } from "node:events"; +import { createServer } from "node:http"; import { Server } from "socket.io"; import { io as socketioClient } from "socket.io-client";