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

Support non-strict JSON body (number)

Open mct-dev opened this issue 4 years ago • 0 comments

Currently, when not treating a request body as a buffer, the Content-Length header is set in prepareProxyReq by the bufferOrString method.

image

When a request contains a JSON body with a number value, such as 12345, this method (bufferOrString) will return undefined instead of the body length. A number value can be valid JSON. For example, when using the body-parser package, you set strict: false to allow this type of JSON.

This results in an error later on when the _http-client package attempts to set header values. It validates these headers and throws an error when finding undefined as the value for Content-Length:

image

Solution here could probably be just to also handle the number data type when setting bodyContent in prepareProxyReq.

mct-dev avatar Nov 04 '20 18:11 mct-dev