Skip to content

Added option for http response headers #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 11 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ if (argv.h || argv.help) {
' -S --ssl Enable https.',
' -C --cert Path to ssl cert file (default: cert.pem).',
' -K --key Path to ssl key file (default: key.pem).',
' -H --header Add extra header to all responses, eg. "X-Frame-Options: DENY"',
'',
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]',
' -h --help Print this list and exit.'
@@ -109,6 +110,16 @@ function listen(port) {
}
}

var extraHeaders = argv.H || argv.header;
if (extraHeaders) {
if (Array.isArray(extraHeaders)) {
options.extraHeaders = extraHeaders;
}
else {
options.extraHeaders = [extraHeaders];
}
}

if (ssl) {
options.https = {
cert: argv.C || argv.cert || 'cert.pem',
7 changes: 7 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
@@ -76,6 +76,13 @@ function HttpServer(options) {
} : null));
}

if (options.extraHeaders) {
options.extraHeaders.forEach(function (header) {
var split = header.split(/:(.+)?/);
this.headers[split[0]] = split[1];
}, this);
}

if (options.robots) {
before.push(function (req, res) {
if (req.url === '/robots.txt') {