Open
Description
Runtime
node.js
Runtime version
16.18.1
Module version
21.3.3
Last module version without issue
No response
Used with
No response
Any other relevant information
No response
What are you trying to achieve or the steps to reproduce?
- Define a strategy
- Define a post route for uploading large files (e.g. an image)
- Assign the previously defined strategy to the route
- Define a form-data client call to load a large file (e.g. 3/4 MB)
Below is the hapi server code to reproduce the error
const Hapi = require('@hapi/hapi')
const {unauthorized} = require('@hapi/boom')
const server = Hapi.server({
port: 3000,
host: 'localhost',
})
server.auth.scheme('testScheme', () => {
return {
authenticate: async (request, h) => {
const err = unauthorized('Unauthorized from testScheme')
return h.unauthenticated(err)
}
}
})
async function init() {
server.auth.strategy('testStrategy', 'testScheme')
server.route({
method: 'POST',
path: '/upload',
options: {
auth: {
strategy: 'testStrategy'
},
payload: {
maxBytes: 10 * 1024 * 1024,
output: 'stream',
parse: true,
allow: 'multipart/form-data',
},
},
handler: async (request, h) => {
const { payload } = request
const file = payload.file
const filename = file.hapi.filename
const data = file._data
return h.response({ message: 'File uploaded successfully' })
},
});
await server.start()
console.log('Server running on %s', server.info.uri)
}
process.on('unhandledRejection', (err) => {
console.log(err)
process.exit(1)
})
init()
What was the result you got?
If the defined strategy returns an unauthorized route error, a "no response" is returned to the client
What result did you expect?
I expect it to return error 401