Skip to content

Commit 0dd22cc

Browse files
authored
Merge pull request #22 from Netail/fix/node-namepsace
fix: prefix node namespace
2 parents 44536d7 + cb2c460 commit 0dd22cc

34 files changed

+71
-71
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ the tests subdirectory.
162162
#### Setup a basic stand-alone proxy server
163163

164164
```js
165-
import * as http from "http";
165+
import * as http from "node:http";
166166
import { createProxyServer } from "http-proxy-3";
167167

168168
// 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
192192
and also you can put your own logic to handle the request.
193193

194194
```js
195-
import * as http from "http";
195+
import * as http from "node:http";
196196
import { createProxyServer } from "http-proxy-3";
197197

198198
// 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
219219
modifies the outgoing proxy request by adding a special header.
220220

221221
```js
222-
import * as http from "http";
222+
import * as http from "node:http";
223223
import { createProxyServer } from "http-proxy-3";
224224

225225
// 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
261261
#### Setup a stand-alone proxy server with latency
262262

263263
```js
264-
import * as http from "http";
264+
import * as http from "node:http";
265265
import { createProxyServer } from "http-proxy-3";
266266

267267
// Create a proxy server with latency
@@ -372,7 +372,7 @@ httpProxy
372372
Also you can proxy the websocket requests just calling the `ws(req, socket, head)` method.
373373

374374
```js
375-
import * as http from "http";
375+
import * as http from "node:http";
376376
import { createProxyServer } from "http-proxy-3";
377377

378378
// Setup our server to proxy standard HTTP requests

lib/http-proxy/common.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { NormalizedServerOptions, ProxyTargetDetailed, ServerOptions } from "./index";
2-
import { type IncomingMessage as Request } from "http";
3-
import { TLSSocket } from "tls";
4-
import type { Socket } from "net";
5-
import * as urllib from "url";
2+
import { type IncomingMessage as Request } from "node:http";
3+
import { TLSSocket } from "node:tls";
4+
import type { Socket } from "node:net";
5+
import * as urllib from "node:url";
66

77
const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
88

@@ -149,16 +149,16 @@ export function setupSocket(socket: Socket): Socket {
149149
export function getPort(
150150
// Incoming HTTP request.
151151
req: Request,
152-
): // Retjurn the port number, as a string.
153-
string {
152+
// Return the port number, as a string.
153+
): string {
154154
const res = req.headers.host ? req.headers.host.match(/:(\d+)/) : "";
155155
return res ? res[1] : hasEncryptedConnection(req) ? "443" : "80";
156156
}
157157

158158
// Check if the request has an encrypted connection.
159159
export function hasEncryptedConnection(
160-
req: // Incoming HTTP request.
161-
Request,
160+
// Incoming HTTP request.
161+
req: Request,
162162
): boolean {
163163
const conn = req.connection;
164164
return (

lib/http-proxy/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as http from "http";
2-
import * as https from "https";
3-
import * as net from "net";
1+
import * as http from "node:http";
2+
import * as https from "node:https";
3+
import * as net from "node:net";
44
import { WEB_PASSES } from "./passes/web-incoming";
55
import { WS_PASSES } from "./passes/ws-incoming";
6-
import { EventEmitter } from "events";
7-
import type { Stream } from "stream";
6+
import { EventEmitter } from "node:events";
7+
import type { Stream } from "node:stream";
88
import debug from "debug";
99
import { toURL } from "./common";
1010

lib/http-proxy/passes/web-incoming.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ The names of passes are exported as WEB_PASSES from this module.
77
88
*/
99

10-
import * as http from "http";
11-
import * as https from "https";
10+
import * as http from "node:http";
11+
import * as https from "node:https";
1212
import { OUTGOING_PASSES } from "./web-outgoing";
1313
import * as common from "../common";
1414
import * as followRedirects from "follow-redirects";
1515
import {
1616
type IncomingMessage as Request,
1717
type ServerResponse as Response,
18-
} from "http";
19-
import { type Socket } from "net";
18+
} from "node:http";
19+
import { type Socket } from "node:net";
2020
import type { ErrorCallback, NormalizedServerOptions, NormalizeProxyTarget, ProxyServer, ProxyTarget, ProxyTargetUrl, ServerOptions } from "..";
2121

2222
export type ProxyResponse = Request & {

lib/http-proxy/passes/ws-incoming.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ flexible.
88
The names of passes are exported as WS_PASSES from this module.
99
*/
1010

11-
import * as http from "http";
12-
import * as https from "https";
11+
import * as http from "node:http";
12+
import * as https from "node:https";
1313
import * as common from "../common";
1414
import type { Request } from "./web-incoming";
15-
import type { Socket } from "net";
15+
import type { Socket } from "node:net";
1616
import debug from "debug";
1717
import type { NormalizedServerOptions, ProxyServer } from "..";
1818

lib/test/balancer/simple-balancer-with-websockets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Simple round robin load balancer for websockets
44
pnpm test ./simple-balancer-with-websockets.test.ts
55
*/
66

7-
import * as http from "http";
7+
import * as http from "node:http";
88
import * as httpProxy from "../..";
99
import getPort from "../get-port";
10-
import { once } from "events";
10+
import { once } from "node:events";
1111
import fetch from "node-fetch";
1212

1313
describe("A simple round-robin load balancer that supports websockets", () => {

lib/test/balancer/simple-balancer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ simple-balancer.test.ts: Example of a simple round robin HTTP load balancer
44
pnpm test simple-balancer.test.ts
55
*/
66

7-
import * as http from "http";
7+
import * as http from "node:http";
88
import * as httpProxy from "../..";
99
import getPort from "../get-port";
1010
import fetch from "node-fetch";

lib/test/get-port.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createServer } from "http";
1+
import { createServer } from "node:http";
22

33
export default async function getPort(): Promise<number> {
44
return new Promise((resolve, reject) => {
@@ -14,4 +14,4 @@ export default async function getPort(): Promise<number> {
1414
});
1515
server.on("error", reject);
1616
});
17-
}
17+
}

lib/test/http/basic-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DEVELOPMENT:
66
pnpm test basic-proxy.test.ts
77
*/
88

9-
import * as http from "http";
9+
import * as http from "node:http";
1010
import * as httpProxy from "../..";
1111
import log from "../log";
1212
import getPort from "../get-port";

lib/test/http/custom-proxy-error.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pnpm test ./custom-proxy-error.test.ts
55
*/
66

77
import * as httpProxy from "../..";
8-
import * as http from "http";
8+
import * as http from "node:http";
99
import getPort from "../get-port";
1010
import fetch from "node-fetch";
1111

0 commit comments

Comments
 (0)