diff --git a/bin/http-server b/bin/http-server index a432dd3e4..169ac14b9 100755 --- a/bin/http-server +++ b/bin/http-server @@ -26,6 +26,7 @@ if (argv.h || argv.help) { ' -s --silent Suppress log messages from output', ' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header', ' Optionally provide CORS headers list separated by commas', + ' --contentType Use a custom Content-Type response header for all requests', ' -o [path] Open browser window after starting the server', ' -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.', ' To disable caching, use -c-1.', @@ -109,6 +110,10 @@ function listen(port) { } } + if (argv.contentType) { + options.contentType = argv.contentType; + } + if (ssl) { options.https = { cert: argv.C || argv.cert || 'cert.pem', diff --git a/lib/http-server.js b/lib/http-server.js index 8d849109e..96662aab3 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -64,6 +64,10 @@ function HttpServer(options) { res.emit('next'); }); + if (options.contentType) { + this.headers['Content-Type'] = options.contentType; + } + if (options.cors) { this.headers['Access-Control-Allow-Origin'] = '*'; this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';