Skip to content

Commit

Permalink
view engine respond method merges headers provided in options paramet…
Browse files Browse the repository at this point in the history
…er with default headers instead of replaces

Closes Issue #61
  • Loading branch information
Nathan committed May 3, 2013
1 parent 33d514b commit 85e4d48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/view.js
Expand Up @@ -83,9 +83,13 @@ ViewEngine.prototype.respond = function(view, opts) {
opts = opts || {};

return q.when(viewEngine.render(view, opts), function(str) {
var headers = _.extend({}, {
'content-type': 'text/html',
'content-length': Buffer.byteLength(str, 'utf-8')
}, opts.headers);
return {
status: opts.status || 200,
headers: opts.headers || { 'content-type': 'text/html', 'content-length': Buffer.byteLength(str, 'utf-8') },
headers: headers,
body: [str]
};
});
Expand Down
22 changes: 22 additions & 0 deletions test/view.test.js
Expand Up @@ -28,3 +28,25 @@ test('test render mustache with partials', function(t) {
t.fail(err);
});
});

test('test `bogart.respond` merges headers', function(t) {
var viewEngine = bogart.viewEngine('mustache', fixturesPath)
, headers = { abc: 123 }
, respondOpts = {
layout: false,
locals: { greeting: {} },
headers: headers
};

when(viewEngine.respond('partial-test.mustache', respondOpts), function(response) {
t.equals(response.headers.abc, headers.abc);
t.equals(response.headers['content-type'], 'text/html');

t.end();
}, function(err) {
t.fail(err);
t.end();
});

t.plan(2);
});

0 comments on commit 85e4d48

Please sign in to comment.