Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer response with binary status validation always throws 500 #4467

Open
figuernd opened this issue Oct 17, 2023 · 1 comment
Open

Buffer response with binary status validation always throws 500 #4467

figuernd opened this issue Oct 17, 2023 · 1 comment
Labels
support Questions, discussions, and general support

Comments

@figuernd
Copy link

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:

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:

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".

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

        throw Boom.badImplementation('Cannot validate non-object response');
    }
@figuernd figuernd added the support Questions, discussions, and general support label Oct 17, 2023
@figuernd
Copy link
Author

My workaround has been to simply remove status validation from the config altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant