Open GiuliaBusnelli opened 6 years ago
Not sure what's happening.
Providing some extra information on the target server and its configuration might help.
Even better would be to provide a minimal setup in which this issue can be reproduced.
I meet the same quetion too, when i use the proxy ,the chrome show net::ERR_CONNECTION_RESET, when without proxy, chrome shows 413 (Request Entity Too Large)
Think this is an issue for the upstream library http-proxy
.
Try creating a issue on their issue tracker: https://github.com/nodejitsu/node-http-proxy/issues
To help out investigation; Is it reproducible with just the http-proxy
library?
You can use a their example: https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/reverse-proxy.js
I looked at this issue node-http-proxy. Found it quite similar to this issue. Try this
onProxyReq: (proxyReq, req, res) => {
const contentType = proxyReq.getHeader('Content-Type');
let bodyData;
if (contentType === 'application/json') {
bodyData = JSON.stringify(req.body);
}
if (contentType === 'application/x-www-form-urlencoded') {
bodyData = queryString.stringify(req.body);
}
if (bodyData) {
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
}
@ConsidNdr Thank you soo much. It is working for me..
I need to proxy a multipart upload request from a web application to an API server. The target server checks the file size and if it is bigger than expected return a 413 - Payload Too Large with a message.
If I send the request directly to the API server, I get the expected 413. But if I send the request to the proxy, the connection is reset.
Setup
Code
Here is my code
If I add the following snippet of code as an option
this is what is printed:
So it seems to me that the proxy receives the expected response form the API server but then it does not forward it correctly.
Can someone please help me fix this issue? Let me know if I must add more information and feel free to ask questions.