diff --git a/bin/http-server b/bin/http-server index a432dd3e..e12f48d0 100755 --- a/bin/http-server +++ b/bin/http-server @@ -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', diff --git a/lib/http-server.js b/lib/http-server.js index 8d849109..5ba5459f 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -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') {