http-proxy-middleware 4.0.0-beta.0 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +41 -40
  2. package/dist/configuration.d.ts +3 -2
  3. package/dist/configuration.js +3 -6
  4. package/dist/debug.d.ts +1 -1
  5. package/dist/debug.js +2 -5
  6. package/dist/errors.js +2 -5
  7. package/dist/factory-hono.d.ts +25 -0
  8. package/dist/factory-hono.js +42 -0
  9. package/dist/factory.d.ts +2 -2
  10. package/dist/factory.js +3 -6
  11. package/dist/get-plugins.d.ts +3 -2
  12. package/dist/get-plugins.js +4 -7
  13. package/dist/handlers/fix-request-body.js +18 -7
  14. package/dist/handlers/index.d.ts +1 -1
  15. package/dist/handlers/index.js +1 -17
  16. package/dist/handlers/public.d.ts +2 -2
  17. package/dist/handlers/public.js +2 -7
  18. package/dist/handlers/response-interceptor.js +6 -9
  19. package/dist/http-proxy-middleware.d.ts +4 -3
  20. package/dist/http-proxy-middleware.js +30 -41
  21. package/dist/index.d.ts +5 -8
  22. package/dist/index.js +4 -23
  23. package/dist/logger.d.ts +1 -1
  24. package/dist/logger.js +1 -4
  25. package/dist/path-filter.d.ts +2 -2
  26. package/dist/path-filter.js +7 -11
  27. package/dist/path-rewriter.js +8 -11
  28. package/dist/plugins/default/debug-proxy-errors-plugin.d.ts +1 -1
  29. package/dist/plugins/default/debug-proxy-errors-plugin.js +3 -7
  30. package/dist/plugins/default/error-response-plugin.d.ts +1 -1
  31. package/dist/plugins/default/error-response-plugin.js +5 -9
  32. package/dist/plugins/default/index.d.ts +4 -4
  33. package/dist/plugins/default/index.js +4 -20
  34. package/dist/plugins/default/logger-plugin.d.ts +1 -1
  35. package/dist/plugins/default/logger-plugin.js +8 -12
  36. package/dist/plugins/default/proxy-events.d.ts +1 -1
  37. package/dist/plugins/default/proxy-events.js +5 -9
  38. package/dist/router.js +5 -8
  39. package/dist/status-code.js +1 -4
  40. package/dist/types.d.ts +6 -6
  41. package/dist/types.js +1 -2
  42. package/dist/utils/function.js +1 -4
  43. package/dist/utils/logger-plugin.js +1 -4
  44. package/dist/utils/sanitize.js +1 -4
  45. package/package.json +36 -27
  46. package/dist/legacy/create-proxy-middleware.d.ts +0 -12
  47. package/dist/legacy/create-proxy-middleware.js +0 -16
  48. package/dist/legacy/index.d.ts +0 -1
  49. package/dist/legacy/index.js +0 -17
  50. package/dist/legacy/options-adapter.d.ts +0 -6
  51. package/dist/legacy/options-adapter.js +0 -97
  52. package/dist/legacy/public.d.ts +0 -2
  53. package/dist/legacy/public.js +0 -5
  54. package/dist/legacy/types.d.ts +0 -111
  55. package/dist/legacy/types.js +0 -2
package/README.md CHANGED
@@ -5,20 +5,19 @@
5
5
  [![Known Vulnerabilities](https://snyk.io/test/github/chimurai/http-proxy-middleware/badge.svg)](https://snyk.io/test/github/chimurai/http-proxy-middleware)
6
6
  [![npm](https://img.shields.io/npm/v/http-proxy-middleware?color=%23CC3534&style=flat-square&logo=npm)](https://www.npmjs.com/package/http-proxy-middleware)
7
7
 
8
- Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/expressjs/express), [next.js](https://github.com/vercel/next.js) and [many more](#compatible-servers).
8
+ Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/expressjs/express), [next.js](https://github.com/vercel/next.js), [hono](https://github.com/honojs/hono) and [many more](#compatible-servers).
9
9
 
10
- Powered by the popular Nodejitsu [`http-proxy`](https://github.com/http-party/node-http-proxy). [![GitHub stars](https://img.shields.io/github/stars/http-party/node-http-proxy.svg?style=social&label=Star)](https://github.com/http-party/node-http-proxy)
10
+ Powered by [`httpxy`](https://github.com/unjs/httpxy). A maintained version of [http-proxy](https://github.com/http-party/node-http-proxy).
11
11
 
12
12
  ## ⚠️ Note <!-- omit in toc -->
13
13
 
14
- This page is showing documentation for version v3.x.x ([release notes](https://github.com/chimurai/http-proxy-middleware/releases))
14
+ This page is showing documentation for version **v4.x.x** ([release notes](https://github.com/chimurai/http-proxy-middleware/releases))
15
15
 
16
- See [MIGRATION.md](https://github.com/chimurai/http-proxy-middleware/blob/master/MIGRATION.md) for details on how to migrate from v2.x.x to v3.x.x
16
+ For older documentation:
17
17
 
18
- If you're looking for older documentation. Go to:
19
-
20
- - <https://github.com/chimurai/http-proxy-middleware/tree/v2.0.4#readme>
21
- - <https://github.com/chimurai/http-proxy-middleware/tree/v0.21.0#readme>
18
+ - [v3.0.5](https://github.com/chimurai/http-proxy-middleware/tree/v3.0.5#readme)
19
+ - [v2.0.4](https://github.com/chimurai/http-proxy-middleware/tree/v2.0.4#readme)
20
+ - [v0.21.0](https://github.com/chimurai/http-proxy-middleware/tree/v0.21.0#readme)
22
21
 
23
22
  ## TL;DR <!-- omit in toc -->
24
23
 
@@ -28,7 +27,7 @@ Proxy `/api` requests to `http://www.example.org`
28
27
 
29
28
  ```typescript
30
29
  // typescript
31
- import * as express from 'express';
30
+ import express from 'express';
32
31
  import type { NextFunction, Request, Response } from 'express';
33
32
  import { createProxyMiddleware } from 'http-proxy-middleware';
34
33
  import type { Filter, Options, RequestHandler } from 'http-proxy-middleware';
@@ -48,7 +47,7 @@ app.listen(3000);
48
47
  // http://127.0.0.1:3000/api/foo/bar -> http://www.example.org/api/foo/bar
49
48
  ```
50
49
 
51
- _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#options) can be used, along with some extra `http-proxy-middleware` [options](#options).
50
+ _All_ `httpxy` [options](https://github.com/unjs/httpxy#options) can be used, along with some extra `http-proxy-middleware` [options](#options).
52
51
 
53
52
  ## Table of Contents <!-- omit in toc -->
54
53
 
@@ -65,8 +64,8 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
65
64
  - [`plugins` (Array)](#plugins-array)
66
65
  - [`ejectPlugins` (boolean) default: `false`](#ejectplugins-boolean-default-false)
67
66
  - [`logger` (Object)](#logger-object)
68
- - [`http-proxy` events](#http-proxy-events)
69
- - [`http-proxy` options](#http-proxy-options)
67
+ - [`httpxy` events](#httpxy-events)
68
+ - [`httpxy` options](#httpxy-options)
70
69
  - [WebSocket](#websocket)
71
70
  - [External WebSocket upgrade](#external-websocket-upgrade)
72
71
  - [Intercept and manipulate requests](#intercept-and-manipulate-requests)
@@ -93,7 +92,7 @@ npm install --save-dev http-proxy-middleware
93
92
  Create and configure a proxy middleware with: `createProxyMiddleware(config)`.
94
93
 
95
94
  ```javascript
96
- const { createProxyMiddleware } = require('http-proxy-middleware');
95
+ import { createProxyMiddleware } from 'http-proxy-middleware';
97
96
 
98
97
  const apiProxy = createProxyMiddleware({
99
98
  target: 'http://www.example.org',
@@ -114,13 +113,13 @@ An example with `express` server.
114
113
 
115
114
  ```javascript
116
115
  // include dependencies
117
- const express = require('express');
118
- const { createProxyMiddleware } = require('http-proxy-middleware');
116
+ import express from 'express';
117
+ import { createProxyMiddleware } from 'http-proxy-middleware';
119
118
 
120
119
  const app = express();
121
120
 
122
121
  // create the proxy
123
- /** @type {import('http-proxy-middleware/dist/types').RequestHandler<express.Request, express.Response>} */
122
+ /** @type {import('http-proxy-middleware').RequestHandler<import('express').Request, import('express').Response>} */
124
123
  const exampleProxy = createProxyMiddleware({
125
124
  target: 'http://www.example.org/api', // target host with the same base path
126
125
  changeOrigin: true, // needed for virtual hosted sites
@@ -281,13 +280,15 @@ NOTE: register your own error handlers to prevent server from crashing.
281
280
 
282
281
  ```js
283
282
  // eject default plugins and manually add them back
284
-
285
- const {
286
- debugProxyErrorsPlugin, // subscribe to proxy errors to prevent server from crashing
287
- loggerPlugin, // log proxy events to a logger (ie. console)
288
- errorResponsePlugin, // return 5xx response on proxy error
283
+ import {
284
+ debugProxyErrorsPlugin,
285
+ // log proxy events to a logger (ie. console)
286
+ errorResponsePlugin,
287
+ // subscribe to proxy errors to prevent server from crashing
288
+ loggerPlugin,
289
+ // return 5xx response on proxy error
289
290
  proxyEventsPlugin, // implements the "on:" option
290
- } = require('http-proxy-middleware');
291
+ } from 'http-proxy-middleware';
291
292
 
292
293
  createProxyMiddleware({
293
294
  target: `http://example.org`,
@@ -313,9 +314,9 @@ createProxyMiddleware({
313
314
  });
314
315
  ```
315
316
 
316
- ## `http-proxy` events
317
+ ## `httpxy` events
317
318
 
318
- Subscribe to [http-proxy events](https://github.com/nodejitsu/node-http-proxy#listening-for-proxy-events) with the `on` option:
319
+ Subscribe to [httpxy events](https://github.com/unjs/httpxy#events) with the `on` option:
319
320
 
320
321
  ```js
321
322
  createProxyMiddleware({
@@ -354,7 +355,7 @@ createProxyMiddleware({
354
355
  }
355
356
  ```
356
357
 
357
- - **option.on.proxyReq**: function, subscribe to http-proxy's `proxyReq` event.
358
+ - **option.on.proxyReq**: function, subscribe to httpxy's `proxyReq` event.
358
359
 
359
360
  ```javascript
360
361
  function onProxyReq(proxyReq, req, res) {
@@ -364,7 +365,7 @@ createProxyMiddleware({
364
365
  }
365
366
  ```
366
367
 
367
- - **option.on.proxyReqWs**: function, subscribe to http-proxy's `proxyReqWs` event.
368
+ - **option.on.proxyReqWs**: function, subscribe to httpxy's `proxyReqWs` event.
368
369
 
369
370
  ```javascript
370
371
  function onProxyReqWs(proxyReq, req, socket, options, head) {
@@ -373,7 +374,7 @@ createProxyMiddleware({
373
374
  }
374
375
  ```
375
376
 
376
- - **option.on.open**: function, subscribe to http-proxy's `open` event.
377
+ - **option.on.open**: function, subscribe to httpxy's `open` event.
377
378
 
378
379
  ```javascript
379
380
  function onOpen(proxySocket) {
@@ -382,7 +383,7 @@ createProxyMiddleware({
382
383
  }
383
384
  ```
384
385
 
385
- - **option.on.close**: function, subscribe to http-proxy's `close` event.
386
+ - **option.on.close**: function, subscribe to httpxy's `close` event.
386
387
 
387
388
  ```javascript
388
389
  function onClose(res, socket, head) {
@@ -391,9 +392,9 @@ createProxyMiddleware({
391
392
  }
392
393
  ```
393
394
 
394
- ## `http-proxy` options
395
+ ## `httpxy` options
395
396
 
396
- The following options are provided by the underlying [http-proxy](https://github.com/nodejitsu/node-http-proxy#options) library.
397
+ The following options are provided by the underlying [httpxy](https://github.com/unjs/httpxy#options) library.
397
398
 
398
399
  - **option.target**: url string to be parsed with the url module
399
400
  - **option.forward**: url string to be parsed with the url module
@@ -448,13 +449,12 @@ The following options are provided by the underlying [http-proxy](https://github
448
449
  - **option.buffer**: stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.g. If you read the body of a request into a field called 'req.rawbody' you could restream this field in the buffer option:
449
450
 
450
451
  ```javascript
451
- 'use strict';
452
+ import { createProxyServer } from 'httpxy';
453
+ import streamify from 'stream-array';
452
454
 
453
- const streamify = require('stream-array');
454
- const HttpProxy = require('http-proxy');
455
- const proxy = new HttpProxy();
455
+ const proxy = createProxyServer();
456
456
 
457
- module.exports = (req, res, next) => {
457
+ export default function proxyWithBody(req, res, next) {
458
458
  proxy.web(
459
459
  req,
460
460
  res,
@@ -464,7 +464,7 @@ The following options are provided by the underlying [http-proxy](https://github
464
464
  },
465
465
  next,
466
466
  );
467
- };
467
+ }
468
468
  ```
469
469
 
470
470
  ## WebSocket
@@ -497,7 +497,7 @@ Currently the only pre-provided request interceptor is `fixRequestBody`, which i
497
497
  Example:
498
498
 
499
499
  ```javascript
500
- const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware');
500
+ import { createProxyMiddleware, fixRequestBody } from 'http-proxy-middleware';
501
501
 
502
502
  const proxy = createProxyMiddleware({
503
503
  /**
@@ -522,7 +522,7 @@ NOTE: `responseInterceptor` disables streaming of target's response.
522
522
  Example:
523
523
 
524
524
  ```javascript
525
- const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
525
+ import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
526
526
 
527
527
  const proxy = createProxyMiddleware({
528
528
  /**
@@ -592,6 +592,7 @@ View the [recipes](https://github.com/chimurai/http-proxy-middleware/tree/master
592
592
 
593
593
  - [connect](https://www.npmjs.com/package/connect)
594
594
  - [express](https://www.npmjs.com/package/express)
595
+ - [hono](https://www.npmjs.com/package/@hono/node-server)
595
596
  - [next.js](https://www.npmjs.com/package/next)
596
597
  - [fastify](https://www.npmjs.com/package/fastify)
597
598
  - [browser-sync](https://www.npmjs.com/package/browser-sync)
@@ -623,7 +624,7 @@ $ yarn build
623
624
  $ yarn test
624
625
 
625
626
  # code coverage
626
- $ yarn cover
627
+ $ yarn coverage
627
628
 
628
629
  # check spelling mistakes
629
630
  $ yarn spellcheck
@@ -637,4 +638,4 @@ $ yarn spellcheck
637
638
 
638
639
  The MIT License (MIT)
639
640
 
640
- Copyright (c) 2015-2025 Steven Chim
641
+ Copyright (c) 2015-2026 Steven Chim
@@ -1,2 +1,3 @@
1
- import { Options } from './types';
2
- export declare function verifyConfig<TReq, TRes>(options: Options<TReq, TRes>): void;
1
+ import type * as http from 'node:http';
2
+ import { Options } from './types.js';
3
+ export declare function verifyConfig<TReq extends http.IncomingMessage, TRes extends http.ServerResponse>(options: Options<TReq, TRes>): void;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyConfig = verifyConfig;
4
- const errors_1 = require("./errors");
5
- function verifyConfig(options) {
1
+ import { ERRORS } from './errors.js';
2
+ export function verifyConfig(options) {
6
3
  if (!options.target && !options.router) {
7
- throw new Error(errors_1.ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
4
+ throw new Error(ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
8
5
  }
9
6
  }
package/dist/debug.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as createDebug from 'debug';
1
+ import createDebug from 'debug';
2
2
  /**
3
3
  * Debug instance with the given namespace: http-proxy-middleware
4
4
  */
package/dist/debug.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Debug = void 0;
4
- const createDebug = require("debug");
1
+ import createDebug from 'debug';
5
2
  /**
6
3
  * Debug instance with the given namespace: http-proxy-middleware
7
4
  */
8
- exports.Debug = createDebug('http-proxy-middleware');
5
+ export const Debug = createDebug('http-proxy-middleware');
package/dist/errors.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ERRORS = void 0;
4
- var ERRORS;
1
+ export var ERRORS;
5
2
  (function (ERRORS) {
6
3
  ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
7
4
  ERRORS["ERR_CONTEXT_MATCHER_GENERIC"] = "[HPM] Invalid pathFilter. Expecting something like: \"/api\" or [\"/api\", \"/ajax\"]";
8
5
  ERRORS["ERR_CONTEXT_MATCHER_INVALID_ARRAY"] = "[HPM] Invalid pathFilter. Plain paths (e.g. \"/api\") can not be mixed with globs (e.g. \"/api/**\"). Expecting something like: [\"/api\", \"/ajax\"] or [\"/api/**\", \"!**.html\"].";
9
6
  ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function";
10
- })(ERRORS || (exports.ERRORS = ERRORS = {}));
7
+ })(ERRORS || (ERRORS = {}));
@@ -0,0 +1,25 @@
1
+ import type { HttpBindings } from '@hono/node-server';
2
+ import type { MiddlewareHandler } from 'hono';
3
+ import { type Options } from './index.js';
4
+ /**
5
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
6
+ *
7
+ * `@remarks`
8
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
9
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
10
+ *
11
+ * `@experimental` This API is experimental and may change without a major version bump.
12
+ *
13
+ * `@example`
14
+ * ```ts
15
+ * import { serve } from '@hono/node-server';
16
+ * import { Hono } from 'hono';
17
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
18
+ *
19
+ * const app = new Hono();
20
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
21
+ * serve(app);
22
+ */
23
+ export declare function createHonoProxyMiddleware(options: Options): MiddlewareHandler<{
24
+ Bindings: HttpBindings;
25
+ }>;
@@ -0,0 +1,42 @@
1
+ import { createProxyMiddleware } from './index.js';
2
+ import { getLogger } from './logger.js';
3
+ /**
4
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
5
+ *
6
+ * `@remarks`
7
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
8
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
9
+ *
10
+ * `@experimental` This API is experimental and may change without a major version bump.
11
+ *
12
+ * `@example`
13
+ * ```ts
14
+ * import { serve } from '@hono/node-server';
15
+ * import { Hono } from 'hono';
16
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
17
+ *
18
+ * const app = new Hono();
19
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
20
+ * serve(app);
21
+ */
22
+ export function createHonoProxyMiddleware(options) {
23
+ const proxy = createProxyMiddleware(options);
24
+ const logger = getLogger(options);
25
+ return (c, next) => {
26
+ return new Promise((resolve, reject) => {
27
+ proxy(c.env.incoming, c.env.outgoing, (err) => {
28
+ if (err) {
29
+ reject(err);
30
+ }
31
+ else {
32
+ resolve();
33
+ }
34
+ });
35
+ })
36
+ .then(() => next())
37
+ .catch((err) => {
38
+ logger.error('Proxy error:', err);
39
+ return c.text('Proxy Error', 500);
40
+ });
41
+ };
42
+ }
package/dist/factory.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type * as http from 'node:http';
2
- import type { NextFunction, Options, RequestHandler } from './types';
3
- export declare function createProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
2
+ import type { NextFunction, Options, RequestHandler } from './types.js';
3
+ export declare function createProxyMiddleware<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
package/dist/factory.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProxyMiddleware = createProxyMiddleware;
4
- const http_proxy_middleware_1 = require("./http-proxy-middleware");
5
- function createProxyMiddleware(options) {
6
- const { middleware } = new http_proxy_middleware_1.HttpProxyMiddleware(options);
1
+ import { HttpProxyMiddleware } from './http-proxy-middleware.js';
2
+ export function createProxyMiddleware(options) {
3
+ const { middleware } = new HttpProxyMiddleware(options);
7
4
  return middleware;
8
5
  }
@@ -1,2 +1,3 @@
1
- import type { Options, Plugin } from './types';
2
- export declare function getPlugins<TReq, TRes>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[];
1
+ import type * as http from 'node:http';
2
+ import type { Options, Plugin } from './types.js';
3
+ export declare function getPlugins<TReq extends http.IncomingMessage, TRes extends http.ServerResponse>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[];
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPlugins = getPlugins;
4
- const default_1 = require("./plugins/default");
5
- function getPlugins(options) {
1
+ import { debugProxyErrorsPlugin, errorResponsePlugin, loggerPlugin, proxyEventsPlugin, } from './plugins/default/index.js';
2
+ export function getPlugins(options) {
6
3
  // don't load default errorResponsePlugin if user has specified their own
7
- const maybeErrorResponsePlugin = options.on?.error ? [] : [default_1.errorResponsePlugin];
4
+ const maybeErrorResponsePlugin = options.on?.error ? [] : [errorResponsePlugin];
8
5
  const defaultPlugins = options.ejectPlugins
9
6
  ? [] // no default plugins when ejecting
10
- : [default_1.debugProxyErrorsPlugin, default_1.proxyEventsPlugin, default_1.loggerPlugin, ...maybeErrorResponsePlugin];
7
+ : [debugProxyErrorsPlugin, proxyEventsPlugin, loggerPlugin, ...maybeErrorResponsePlugin];
11
8
  const userPlugins = options.plugins ?? [];
12
9
  return [...defaultPlugins, ...userPlugins];
13
10
  }
@@ -1,11 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixRequestBody = fixRequestBody;
4
- const querystring = require("node:querystring");
1
+ import * as querystring from 'node:querystring';
2
+ import * as zlib from 'node:zlib';
5
3
  /**
6
4
  * Fix proxied body if bodyParser is involved.
7
5
  */
8
- function fixRequestBody(proxyReq, req) {
6
+ export function fixRequestBody(proxyReq, req) {
9
7
  // skip fixRequestBody() when req.readableLength not 0 (bodyParser failure)
10
8
  if (req.readableLength !== 0) {
11
9
  return;
@@ -19,8 +17,21 @@ function fixRequestBody(proxyReq, req) {
19
17
  return;
20
18
  }
21
19
  const writeBody = (bodyData) => {
22
- proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
23
- proxyReq.write(bodyData);
20
+ let proxyData = bodyData;
21
+ const contentEncoding = String(proxyReq.getHeader('Content-Encoding')).toLowerCase();
22
+ switch (contentEncoding) {
23
+ case 'br':
24
+ proxyData = zlib.brotliCompressSync(proxyData);
25
+ break;
26
+ case 'deflate':
27
+ proxyData = zlib.deflateSync(proxyData);
28
+ break;
29
+ case 'gzip':
30
+ proxyData = zlib.gzipSync(proxyData);
31
+ break;
32
+ }
33
+ proxyReq.setHeader('Content-Length', Buffer.byteLength(proxyData));
34
+ proxyReq.write(proxyData);
24
35
  };
25
36
  // Use if-elseif to prevent multiple writeBody/setHeader calls:
26
37
  // Error: "Cannot set headers after they are sent to the client"
@@ -1 +1 @@
1
- export * from './public';
1
+ export * from './public.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./public"), exports);
1
+ export * from './public.js';
@@ -1,2 +1,2 @@
1
- export { responseInterceptor } from './response-interceptor';
2
- export { fixRequestBody } from './fix-request-body';
1
+ export { responseInterceptor } from './response-interceptor.js';
2
+ export { fixRequestBody } from './fix-request-body.js';
@@ -1,7 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixRequestBody = exports.responseInterceptor = void 0;
4
- var response_interceptor_1 = require("./response-interceptor");
5
- Object.defineProperty(exports, "responseInterceptor", { enumerable: true, get: function () { return response_interceptor_1.responseInterceptor; } });
6
- var fix_request_body_1 = require("./fix-request-body");
7
- Object.defineProperty(exports, "fixRequestBody", { enumerable: true, get: function () { return fix_request_body_1.fixRequestBody; } });
1
+ export { responseInterceptor } from './response-interceptor.js';
2
+ export { fixRequestBody } from './fix-request-body.js';
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.responseInterceptor = responseInterceptor;
4
- const zlib = require("node:zlib");
5
- const debug_1 = require("../debug");
6
- const function_1 = require("../utils/function");
7
- const debug = debug_1.Debug.extend('response-interceptor');
1
+ import * as zlib from 'node:zlib';
2
+ import { Debug } from '../debug.js';
3
+ import { getFunctionName } from '../utils/function.js';
4
+ const debug = Debug.extend('response-interceptor');
8
5
  /**
9
6
  * Intercept responses from upstream.
10
7
  * Automatically decompress (deflate, gzip, brotli).
@@ -12,7 +9,7 @@ const debug = debug_1.Debug.extend('response-interceptor');
12
9
  *
13
10
  * NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
14
11
  */
15
- function responseInterceptor(interceptor) {
12
+ export function responseInterceptor(interceptor) {
16
13
  return async function proxyResResponseInterceptor(proxyRes, req, res) {
17
14
  debug('intercept proxy response');
18
15
  const originalProxyRes = proxyRes;
@@ -25,7 +22,7 @@ function responseInterceptor(interceptor) {
25
22
  // copy original headers
26
23
  copyHeaders(proxyRes, res);
27
24
  // call interceptor with intercepted response (buffer)
28
- debug('call interceptor function: %s', (0, function_1.getFunctionName)(interceptor));
25
+ debug('call interceptor function: %s', getFunctionName(interceptor));
29
26
  const interceptedBuffer = Buffer.from(await interceptor(buffer, originalProxyRes, req, res));
30
27
  // set correct content-length (with double byte character support)
31
28
  debug('set content-length: %s', Buffer.byteLength(interceptedBuffer, 'utf8'));
@@ -1,5 +1,6 @@
1
- import type { Options, RequestHandler } from './types';
2
- export declare class HttpProxyMiddleware<TReq, TRes> {
1
+ import type * as http from 'node:http';
2
+ import type { Options, RequestHandler } from './types.js';
3
+ export declare class HttpProxyMiddleware<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
3
4
  private wsInternalSubscribed;
4
5
  private serverOnCloseSubscribed;
5
6
  private proxyOptions;
@@ -7,7 +8,7 @@ export declare class HttpProxyMiddleware<TReq, TRes> {
7
8
  private pathRewriter;
8
9
  private logger;
9
10
  constructor(options: Options<TReq, TRes>);
10
- middleware: RequestHandler;
11
+ middleware: RequestHandler<TReq, TRes>;
11
12
  private registerPlugins;
12
13
  private catchUpgradeRequest;
13
14
  private handleUpgrade;