Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/http-proxy/common.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions lib/http-proxy/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
8 changes: 4 additions & 4 deletions lib/http-proxy/passes/web-incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down
6 changes: 3 additions & 3 deletions lib/http-proxy/passes/ws-incoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "..";

Expand Down
4 changes: 2 additions & 2 deletions lib/test/balancer/simple-balancer-with-websockets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/test/balancer/simple-balancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions lib/test/get-port.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServer } from "http";
import { createServer } from "node:http";

export default async function getPort(): Promise<number> {
return new Promise((resolve, reject) => {
Expand All @@ -14,4 +14,4 @@ export default async function getPort(): Promise<number> {
});
server.on("error", reject);
});
}
}
2 changes: 1 addition & 1 deletion lib/test/http/basic-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/custom-proxy-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/double-slashes.test.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/forward-and-target-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/forward-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/latent-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/proxy-http-to-https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions lib/test/http/proxy-https-to-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions lib/test/http/proxy-https-to-https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions lib/test/http/reverse-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/http/server-sent-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/lib/http-proxy-passes-web-incoming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/lib/http-proxy-passes-web-outgoing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} };

Expand Down
6 changes: 3 additions & 3 deletions lib/test/lib/http-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/test/lib/https-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/test/middleware/body-decoder-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/middleware/gzip-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/middleware/modify-response-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/test/security/blacklist-headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/test/websocket/latent-websocket-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Loading