Skip to content
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

Multipart upload reset connection #265

Open
GiuliaBusnelli opened this issue May 17, 2018 · 5 comments
Open

Multipart upload reset connection #265

GiuliaBusnelli opened this issue May 17, 2018 · 5 comments

Comments

@GiuliaBusnelli
Copy link

GiuliaBusnelli commented May 17, 2018

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

  • http-proxy-middleware: 0.17.4
  • server: express v4.16.2

Code

Here is my code

// Set request timeout
var setTimeout = function(req, res, next) {
  req.setTimeout(30*60*1000);
  next();
}

// Set up API proxy
var options = {
  logLevel: process.env.LOG_LEVEL || 'info',
  target: process.env.PROXY_TARGET,
  pathRewrite: {
    '^/webapp/api' : '/api'
  },
  onProxyReq: function(proxyReq, req, res) {
    // Add username header to request
    proxyReq.setHeader('X-DevID', req.session[ cas.session_name ]);
  }
}
var apiProxy = proxy(options)

app.use('/graph4u-webapp/api', setTimeout, apiProxy);
var server = app.listen(process.env.PORT)

If I add the following snippet of code as an option

onProxyRes: function(proxyRes, req, res) {
  proxyRes.on('data', function(data) {
    console.log(data.toString('utf-8'));
  });
}

this is what is printed:

{
  "httpStatusValue":413,
  "errorName":"PAYLOAD_TOO_LARGE",
  "message":"La dimensione del file caricato (14MB) supera quella massima consentita (10MB).",
  "url":"..."
}

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.

@chimurai
Copy link
Owner

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.

@qianlongdoit
Copy link

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)

@chimurai
Copy link
Owner

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

@ConsidNdr
Copy link

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);
        }
}

@SivaKrishnaKola
Copy link

@ConsidNdr Thank you soo much. It is working for me..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants