Skip to content

Commit 2fbd74b

Browse files
committed
Adding contentType cli option to address #276
1 parent 1a8552c commit 2fbd74b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

bin/http-server

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if (argv.h || argv.help) {
2626
' -s --silent Suppress log messages from output',
2727
' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header',
2828
' Optionally provide CORS headers list separated by commas',
29+
' --contentType Use a custom Content-Type response header for all requests',
2930
' -o [path] Open browser window after starting the server',
3031
' -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.',
3132
' To disable caching, use -c-1.',
@@ -109,6 +110,10 @@ function listen(port) {
109110
}
110111
}
111112

113+
if (argv.contentType) {
114+
options.contentType = argv.contentType;
115+
}
116+
112117
if (ssl) {
113118
options.https = {
114119
cert: argv.C || argv.cert || 'cert.pem',

lib/http-server.js

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ function HttpServer(options) {
6464
res.emit('next');
6565
});
6666

67+
if (options.contentType) {
68+
this.headers['Content-Type'] = options.contentType;
69+
}
70+
6771
if (options.cors) {
6872
this.headers['Access-Control-Allow-Origin'] = '*';
6973
this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';

0 commit comments

Comments
 (0)