I need to set some response headers within server.onPreHandler ext method. There are 2 scenarios, where I need this happen when user sends an API request to my route end point. 1) In success scenario, I need to set headers and let process continue further down life cycle 2) In error scenario (where user has not provided a required field), I need to set headers and return immediately to user with appropriate error info.
In both of these scenarios, I would like to set response headers. In the 2nd scenario above, I am able to invoke reply.response('error') and then set response header to it using response.header('x', 'value'). However, in the 1st scenario, where before calling reply.continue() I am trying to set header using request.response.header('x', 'value), I get response null error.
Please help
Thanks Ramesh
I'm able to change response headers like this. Have you tried this way?
// at your onPreResponse ext body
const response = request.response;
if (request.response.isBoom) {
response.output.headers['x'] = 'value';
} else {
response.header('x', 'value');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With