express-http-proxy icon indicating copy to clipboard operation
express-http-proxy copied to clipboard

Strange behavior fixed by setting parseReqBody to false

Open murphyke opened this issue 6 years ago • 4 comments

I'm posting this in case it helps anybody. I also suspect there may be something a little off in express-http-proxy, but I don't have time to determine if that's true or not.

I am putting my proxy in between an Elasticsearch client and Elasticsearch. Currently the proxy is merely logging the requests and responses without making any modifications.

With the default value of parseReqBody (true), then a simple request like curl http:/localhost:9201/patient/_count?pretty results in Elasticsearch returning a 406 error with a complaint about an unsupported Content-Type header. That curl command does not produce an error when issued directly to Elasticsearch. Here's the log showing the error:

Proxying from: http://localhost:9201/, to: http://localhost:9200/
Request: GET /patient/_count?pretty
  req.body: {}
    req.headers: {
    "host": "localhost:9201",
    "user-agent": "curl/7.54.0",
    "accept": "*/*"
  }
Response: 406, size 76
  headers: {
    "content-type": "application/json; charset=UTF-8",
    "content-length": "76"
  }
  body: {
    "error": "Content-Type header [] is not supported",
    "status": 406
  } 

However, when the parseReqBody option is set to false, that query is successful:

Proxying from: http://localhost:9201/, to: http://localhost:9200/
Request: GET /patient/_count?pretty
  req.body: {}
  req.headers: {
    "host": "localhost:9201",
    "user-agent": "curl/7.54.0",
    "accept": "*/*"
  }
Response: 200, size 120
  headers: {
    "content-type": "application/json; charset=UTF-8",
    "content-length": "120"
  }
  body: {
    "count": 2877975,
    "_shards": {
      "total": 5,
      "successful": 5,
      "skipped": 0,
      "failed": 0
    }
  } 

I turned on the debugging using the DEBUG environment variable, but it did not reveal any differences in handling.

murphyke avatar Apr 26 '19 14:04 murphyke

Can second this, parseReqBody was causing CloudFront 403 issues for us, disabling did the trick 👍

danitt avatar Jan 02 '20 03:01 danitt

for anyone interested in investigating further, have narrowed the issue down to this conditional: express-http-proxy/app/steps/sendProxyRequest.js:40-68

might be the "proxyReq.end()" on 64 causing troubles

danitt avatar Jan 02 '20 03:01 danitt

have narrowed the issue down to this conditional: express-http-proxy/app/steps/sendProxyRequest.js:40-68

Link: https://github.com/villadora/express-http-proxy/blob/ad94d320390735157133e405969161d82c6ab58d/app/steps/sendProxyRequest.js#L40-L68

john-kurkowski avatar Feb 04 '20 01:02 john-kurkowski

parseReqBody: false Did it for us too. Thanks murphyke

kraeg75 avatar Jan 31 '23 05:01 kraeg75