-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot proxy after parsing body #299
Comments
Looks related to: |
+1 got the same issue. Moving the middlewares before body.json works |
Yes that's correct. I need to parse the body to know if I need to proxy the request though. |
If need to parse the body before proxy, I have followed suggestion from this issue: #177 (comment) |
same issue |
+1 |
1 similar comment
+1 |
This is my solution: https://github.com/stuartZhang/coexist-parser-proxy |
fixed in #492 |
The solutions proposed here worked fine, but after adding an agent (sock5 //
const bodyParser = require('body-parser')
const { Readable } = require('stream');
//
app.use(bodyParser.json({
// verify function has access to buff that contains the stream
// create a new readable stream and save it to streamBody
verify: (req, res, buf, encoding) => {
const readableStream = Readable.from(buf);
req.streamBody = readableStream
}
}));
// Param "buffer" accept a stream if the original one was consumed
app.all("*", (req, res) => proxy.web(req, res, {
target: "target-here",
buffer: req.streamBody
}); |
I cannot re-send a proxied request's body after I have parsed it.
Using this recipe, this comment and this comment I have written the following example:
I get an error when trying to set the first header on the
proxyReq
saying:Cannot set headers after they are sent to the client
.If that is the case how does the recipe work?
The text was updated successfully, but these errors were encountered: