Skip to content

Commit e318398

Browse files
committed
allow returning a response object inside a promise
1 parent a17e98d commit e318398

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/response.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ internals.Response.prototype._prepare = function (data, next) {
368368
return next(Boom.wrap(source), data);
369369
}
370370

371+
if (source instanceof internals.Response) {
372+
return source._processPrepare(data, next);
373+
}
374+
371375
self._setSource(source);
372376
self._passThrough();
373377
self._processPrepare(data, next);

test/response.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,25 @@ describe('Response', function () {
857857
});
858858
});
859859

860+
it('handles promises that resolve (response object)', function (done) {
861+
862+
var handler = function (request, reply) {
863+
864+
return reply(Bluebird.resolve(request.generateResponse({ status: 'ok' }).code(201)));
865+
};
866+
867+
var server = new Hapi.Server();
868+
server.connection();
869+
server.route({ method: 'GET', path: '/', handler: handler });
870+
871+
server.inject('/', function (res) {
872+
873+
expect(res.result.status).to.equal('ok');
874+
expect(res.statusCode).to.equal(201);
875+
done();
876+
});
877+
});
878+
860879
it('handles promises that reject', function (done) {
861880

862881
var handler = function (request, reply) {

0 commit comments

Comments
 (0)