yarn why http-proxy-middleware OR npm ls http-proxy-middleware output (mask private folder names with *****)
├─ server@workspace:packages/server
│ └─ http-proxy-middleware@npm:2.0.1 (via npm:^2.0.1)
Describe the bug (be clear and concise)
The fixRequestBody utility contains a check for empty objects that results in early return:
|
if (!requestBody || !Object.keys(requestBody).length) { |
|
return; |
|
} |
When an empty object request (curl ... -H 'content-type: application/json' -d '{}') is made to a proxy with onProxyReq: fixRequestBody, the request hangs because the target is expecting content-length: 2 but never receives any payload because of the early return. See Steps to Reproduce, below.
Am I missing a reason why empty objects get special handling?
Step-by-step reproduction instructions
1. Run the following script:
const express = require('express')
const bodyParser = require('body-parser')
const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware')
const proxyApp = express()
proxyApp.use(bodyParser.json())
proxyApp.use(createProxyMiddleware({
target: 'http://localhost:8081',
onProxyReq: fixRequestBody
}))
proxyApp.listen(8080)
const app = express()
app.use((req, res, next) => console.log(req.headers) || next())
app.use(bodyParser.json())
app.post('/', (req, res) => res.json(req.body))
app.listen(8081)
2. `curl localhost:8080 -XPOST -H 'content-type: application/json' -d '{"hello":"there"}'` -> `{"hello":"there"}`
3. `curl localhost:8080 -XPOST -H 'content-type: application/json' -d '{}'` -> hangs
Expected behavior (be clear and concise)
I expect an empty object JSON request to be proxied with the request body fixed, the same way as a non-empty object JSON request.
What http-proxy-middleware configuration are you using?
const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware')
app.use(createProxyMiddleware({
target: 'http://localhost:8081',
onProxyReq: fixRequestBody
}))
What OS/version and node/version are you seeing the problem?
MacOS 11.4 and Node 14.15.1
Additional context (optional)
No response
yarn why http-proxy-middlewareORnpm ls http-proxy-middlewareoutput (mask private folder names with *****)http-proxy-middleware.Describe the bug (be clear and concise)
The
fixRequestBodyutility contains a check for empty objects that results in earlyreturn:http-proxy-middleware/src/handlers/fix-request-body.ts
Lines 11 to 13 in c9bec81
When an empty object request (
curl ... -H 'content-type: application/json' -d '{}') is made to a proxy withonProxyReq: fixRequestBody, the request hangs because the target is expectingcontent-length: 2but never receives any payload because of the earlyreturn. See Steps to Reproduce, below.Am I missing a reason why empty objects get special handling?
Step-by-step reproduction instructions
Expected behavior (be clear and concise)
I expect an empty object JSON request to be proxied with the request body fixed, the same way as a non-empty object JSON request.
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
No response