villadora / express-http-proxy

Proxy middleware for express/connect
Other
1.23k stars 234 forks source link

Only set content-length when request is not a GET request #160

Open fetimo opened 7 years ago

fetimo commented 7 years ago

Hi,

An app I'm trying to interact with is throwing a 400 error as this library will stringify an empty body ({}) resulting in a content length of 2, even though the content length of the GET request is 0.

I've submitted a PR that only sets the content-length header if the request is not a GET, I'm open to suggestions for other approaches though.

zavan commented 2 weeks ago

AWS CloudFront doesn't like GET requests with a body.

This fixed it for us:

proxyReqBodyDecorator: (bodyContent, srcReq) => {
  if (srcReq.method === 'GET') return "";
  return bodyContent;
},

Related: #475