Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ var HTTPServer = exports.HTTPServer = function (options) {
this.root = './';
}
}

if (options.headers) {
this.headers = options.headers;
}

this.cache = options.cache || 3600; // in seconds.
this.autoIndex = options.autoIndex !== false;
Expand All @@ -27,7 +31,8 @@ var HTTPServer = exports.HTTPServer = function (options) {
autoIndex: this.autoIndex,
cache: this.cache
})
]
],
headers: this.headers || {}
});
};

Expand Down
16 changes: 14 additions & 2 deletions test/http-server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ vows.describe('http-server').addBatch({
'When http-server is listening on 8080': {
topic: function () {
var server = httpServer.createServer({
root: root
root: root,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true'
}
});
server.listen(8080);
this.callback(null, server);
Expand Down Expand Up @@ -52,7 +56,15 @@ vows.describe('http-server').addBatch({
assert.include(body, '/file');
assert.include(body, '/canYouSeeMe');
}
},
'and options include custom set http-headers': {
topic: function () {
request('http://127.0.0.1:8080/', this.callback);
},
'should respond with headers set in options': function (err, res, body) {
assert.equal(res.headers['access-control-allow-origin'], '*');
assert.equal(res.headers['access-control-allow-credentials'], 'true');
}
}
}
}).export(module);