http-proxy-middleware 2.0.8 → 2.0.9

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.
@@ -3,4 +3,4 @@ import type * as http from 'http';
3
3
  /**
4
4
  * Fix proxied body if bodyParser is involved.
5
5
  */
6
- export declare function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage, res: http.ServerResponse): void;
6
+ export declare function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void;
@@ -5,7 +5,11 @@ const querystring = require("querystring");
5
5
  /**
6
6
  * Fix proxied body if bodyParser is involved.
7
7
  */
8
- function fixRequestBody(proxyReq, req, res) {
8
+ function fixRequestBody(proxyReq, req) {
9
+ // skip fixRequestBody() when req.readableLength not 0 (bodyParser failure)
10
+ if (req.readableLength !== 0) {
11
+ return;
12
+ }
9
13
  const requestBody = req.body;
10
14
  if (!requestBody) {
11
15
  return;
@@ -14,16 +18,6 @@ function fixRequestBody(proxyReq, req, res) {
14
18
  if (!contentType) {
15
19
  return;
16
20
  }
17
- // Handle bad request when unexpected "Connect: Upgrade" header is provided
18
- if (/upgrade/gi.test(proxyReq.getHeader('Connection'))) {
19
- handleBadRequest({ proxyReq, req, res });
20
- return;
21
- }
22
- // Handle bad request when invalid request body is provided
23
- if (hasInvalidKeys(requestBody)) {
24
- handleBadRequest({ proxyReq, req, res });
25
- return;
26
- }
27
21
  const writeBody = (bodyData) => {
28
22
  // deepcode ignore ContentLengthInCode: bodyParser fix
29
23
  proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
@@ -37,12 +31,3 @@ function fixRequestBody(proxyReq, req, res) {
37
31
  }
38
32
  }
39
33
  exports.fixRequestBody = fixRequestBody;
40
- function hasInvalidKeys(obj) {
41
- return Object.keys(obj).some((key) => /[\n\r]/.test(key));
42
- }
43
- function handleBadRequest({ proxyReq, req, res }) {
44
- res.writeHead(400);
45
- res.end('Bad Request');
46
- proxyReq.destroy();
47
- req.destroy();
48
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-proxy-middleware",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "The one-liner node.js proxy middleware for connect, express and browser-sync",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",