hapijs / hapijs/hapi

Buffer response with binary status validation always throws 500

Open
#4,467 1 comment 2 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
14.8k
Forks
1.4k
Avg merge
22d 3h
Merged PRs (30d)
1

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): yes

#### Context

* *node version*: 12
* *module version with issue*: 19.2.0
* *last module version without issue*: Unknown
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): @hapi/hapi
* *any other relevant information*:

#### What are you trying to achieve or the steps to reproduce?

Given this response:

```js
const testBuffer = Buffer.from('hello world', 'binary');
return h.response(csv_results).encoding('binary')
.header('Content-Length', testBuffer.length)
.type('application/octet-stream').code(200);
```

With this config:

```js
response: {
status: {
200: Joi.binary()
},
},
```

#### What was the result you got?

```
Debug: internal, implementation, error
Error: Cannot validate non-object response
at exports.response (/node_modules/@hapi/hapi/lib/validation.js:179:20)
```

#### What result did you expect?

Success/no error.

Observing `@hapi/lib/validation.js`, the error appears to be that the the "binary" response schema is not being honored, with `request.response.variety` being set to "plain" when it should be "buffer".

```js
if (!response.isBoom &&
request.response.variety !== 'plain') {

throw Boom.badImplementation('Cannot validate non-object response');
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.