Strange behavior fixed by setting parseReqBody to false
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.
Can second this, parseReqBody was causing CloudFront 403 issues for us, disabling did the trick 👍
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
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
parseReqBody: false Did it for us too. Thanks murphyke