hapi define the header before sending the answer

advertisements

In a hapi handler I try to set a header of my response earlier in the code before sending back a view.

reply().header('cache-control', 'no-cache');

{....}

reply.view('myView', myContext);

Do you I have to use the hold method? In that case how do I reuse the response when rendering the view?

Thanks for your help.


set header on each response
currently tested in hapi 6.6.0

server.ext('onPreResponse', function(request, reply) {

 request.response.header('X-API-VERSION', '0.0.1');

 reply();

});