seangenabe / etagger

hapi ETag helper plugin
MIT License
2 stars 1 forks source link

Breaking Response Validation with Hapi 19 and Joi 16 #40

Open frankthelen opened 4 years ago

frankthelen commented 4 years ago

We are just upgrading our system from Hapi 18 / Joi 15 to Hapi 19 / Joi 16. What we see is a very strange behavior in conjunction with etagger (5.0.3).

If etagger is plugged-in and enabled, it will cause Hapi to stringify all response payloads before passing them to Joi. This breaks all response validation except Joi.any() or Joi.string(). In our case, pretty much all GET routes, e.g., Joi.array() results in HTTP 500 and ValidationError: \"foo\" must be an array.

If etagger is out, everything is fine like before upgrading.

seangenabe commented 4 years ago

Seems like Hapi v19 broke some things. Tests are failing on Node 10 due to new syntax. Tbh I haven't used Hapi for a long time. If you can submit a PR with a test for your case, that'd be awesome.

frankthelen commented 4 years ago

Looking briefly at your code, I think, this is the problem: response._setSource(newSource, "plain") https://github.com/seangenabe/etagger/blob/master/index.ts#L53 You should not set the response payload to its stringified version.