Define custom content encoding handlers
Right now, body-parser provided out-of-the-box support for gzip, deflate, and identitiy content encodings. This is nice, but we can do even better by allowing users to define custom content encoding hooks that return a stream of the decoded content when provided a stream of encoded content.
Any progress on this? Certain 3rd party API send us webhooks in utf-8 encoding, and bodyparser being in front of all routes forbid us to read their payload. How do I allow "utf-8" content encoding for now?
Also if you set Content-Encoding as "gzip, deflate", it will throw an "unsupported content encoding in the contentstream() method. This method performs a switch case directly matching the header value with the cases "deflate', 'gzip' and 'identity', thus failing if the header value is e.g. the one referred before.
Hi @dougwilson - I have a similar situation wherein the upstream system is sending 'Content-Encoding' header with value = UTF-8 - this is getting rejected by the body-parser upfront. I had previously added the following in correlation-middleware (and included in main.ts) but after version upgrade for nestJs, even this check is not effective anymore.
main.ts -
app.use(correlationMiddleware);
correlation.middleware.ts -
// https://github.com/expressjs/body-parser/issues/100
if (req.headers['content-encoding']) {
delete req.headers['content-encoding'];
}
Any help in this regard would save the day.
Hi @dougwilson - I have a similar situation wherein the upstream system is sending 'Content-Encoding' header with value = UTF-8 - this is getting rejected by the
body-parserupfront. I had previously added the following incorrelation-middleware(and included inmain.ts) but after version upgrade for nestJs, even this check is not effective anymore.main.ts - app.use(correlationMiddleware); correlation.middleware.ts - // https://github.com/expressjs/body-parser/issues/100 if (req.headers['content-encoding']) { delete req.headers['content-encoding']; }Any help in this regard would save the day.
I was able to resolve this by ensuring that the app.use(correlationMiddleware) directive is before the other parser settings.
As below:
Before:
app.use(json({ limit: '1mb' }));
app.use(urlencoded({ extended: true, limit: '1mb' }));
app.use(correlationMiddleware);
After:
app.use(correlationMiddleware);
app.use(json({ limit: '1mb' }));
app.use(urlencoded({ extended: true, limit: '1mb' }));