http-proxy-middleware 2.0.7 → 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.
- package/README.md +1 -1
- package/dist/handlers/fix-request-body.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,20 +6,27 @@ const querystring = require("querystring");
|
|
|
6
6
|
* Fix proxied body if bodyParser is involved.
|
|
7
7
|
*/
|
|
8
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;
|
|
12
16
|
}
|
|
13
17
|
const contentType = proxyReq.getHeader('Content-Type');
|
|
18
|
+
if (!contentType) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
14
21
|
const writeBody = (bodyData) => {
|
|
15
22
|
// deepcode ignore ContentLengthInCode: bodyParser fix
|
|
16
23
|
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
17
24
|
proxyReq.write(bodyData);
|
|
18
25
|
};
|
|
19
|
-
if (contentType
|
|
26
|
+
if (contentType.includes('application/json')) {
|
|
20
27
|
writeBody(JSON.stringify(requestBody));
|
|
21
28
|
}
|
|
22
|
-
if (contentType
|
|
29
|
+
else if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
23
30
|
writeBody(querystring.stringify(requestBody));
|
|
24
31
|
}
|
|
25
32
|
}
|