From 7e368d67fa0856fa3931f1f5b3663f55c57534d1 Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Tue, 5 Oct 2021 21:27:08 -0500 Subject: [PATCH 1/8] Fixes #451 --- bin/http-server | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/http-server b/bin/http-server index 91ced18d..2e239149 100755 --- a/bin/http-server +++ b/bin/http-server @@ -140,6 +140,13 @@ function listen(port) { } } + if (proxy) { + if (!proxy.startsWith('http://') && !proxy.startsWith('https://')) { + logger.info(colors.red('Error: Proxy must specify a protocol')); + process.exit(1); + } + } + if (ssl) { options.https = { cert: argv.C || argv.cert || 'cert.pem', From e8db8dc7776abb219579f3632c3bc6ae49b73bd5 Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Wed, 6 Oct 2021 14:10:44 -0500 Subject: [PATCH 2/8] Added test for issue #451 --- test/cli.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/cli.test.js b/test/cli.test.js index 9eebc882..a46c1a97 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -122,3 +122,16 @@ test('setting mimeTypes via cli - directly', (t) => { }); }); }); + +test('--proxy requires you to specify a protocol', (t) => { + t.plan(1); + + const options = ['.', '--proxy', 'google.com']; + const ecstatic = startEcstatic(options); + + tearDown(ecstatic, t); + + ecstatic.on('exit', (code) => { + t.equal(code, 1); + }); +}); \ No newline at end of file From 0ba1cb3df185aac135a1b1baaccd7fbf9f52b102 Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 12:11:24 -0500 Subject: [PATCH 3/8] Made proxy url checker more general --- bin/http-server | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/http-server b/bin/http-server index 2e239149..d5784b9a 100755 --- a/bin/http-server +++ b/bin/http-server @@ -2,6 +2,8 @@ 'use strict'; +const { url } = require('inspector'); + var colors = require('colors/safe'), os = require('os'), httpServer = require('../lib/http-server'), @@ -9,6 +11,7 @@ var colors = require('colors/safe'), opener = require('opener'), fs = require('fs'), argv = require('minimist')(process.argv.slice(2)); + URL = require('url'); var ifaces = os.networkInterfaces(); process.title = 'http-server'; @@ -141,8 +144,11 @@ function listen(port) { } if (proxy) { - if (!proxy.startsWith('http://') && !proxy.startsWith('https://')) { - logger.info(colors.red('Error: Proxy must specify a protocol')); + try { + new URL.URL(proxy) + } + catch (err) { + logger.info(colors.red('Error: Invalid proxy url')); process.exit(1); } } From 5d55b6af5d86109e387460769f80c9573f21d0c3 Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 12:17:01 -0500 Subject: [PATCH 4/8] Removed accidental require() --- bin/http-server | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/http-server b/bin/http-server index d5784b9a..e2e24c1a 100755 --- a/bin/http-server +++ b/bin/http-server @@ -2,8 +2,6 @@ 'use strict'; -const { url } = require('inspector'); - var colors = require('colors/safe'), os = require('os'), httpServer = require('../lib/http-server'), From 6307b003e4ddd9549c7f6710e092da0e028cad0d Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:04:53 -0500 Subject: [PATCH 5/8] stylistic change Co-authored-by: Jade Michael Thornton --- bin/http-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/http-server b/bin/http-server index e2e24c1a..3ec0f5a4 100755 --- a/bin/http-server +++ b/bin/http-server @@ -9,7 +9,7 @@ var colors = require('colors/safe'), opener = require('opener'), fs = require('fs'), argv = require('minimist')(process.argv.slice(2)); - URL = require('url'); + url = require('url'); var ifaces = os.networkInterfaces(); process.title = 'http-server'; From dbd607cf34b18436d4a0ddbe02f09f1a50aee83d Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:05:00 -0500 Subject: [PATCH 6/8] stylistic change Co-authored-by: Jade Michael Thornton --- bin/http-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/http-server b/bin/http-server index 3ec0f5a4..8340fa9c 100755 --- a/bin/http-server +++ b/bin/http-server @@ -143,7 +143,7 @@ function listen(port) { if (proxy) { try { - new URL.URL(proxy) + new url.URL(proxy) } catch (err) { logger.info(colors.red('Error: Invalid proxy url')); From b80f3d3f1401372864d55883458b30777ed210ac Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 14:22:02 -0500 Subject: [PATCH 7/8] Added missing comma --- bin/http-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/http-server b/bin/http-server index 8340fa9c..676225cb 100755 --- a/bin/http-server +++ b/bin/http-server @@ -8,7 +8,7 @@ var colors = require('colors/safe'), portfinder = require('portfinder'), opener = require('opener'), fs = require('fs'), - argv = require('minimist')(process.argv.slice(2)); + argv = require('minimist')(process.argv.slice(2)), url = require('url'); var ifaces = os.networkInterfaces(); From 046fefa1402ba84aff75997de66aedd99f743372 Mon Sep 17 00:00:00 2001 From: Ratcoder <69884239+Ratcoder@users.noreply.github.com> Date: Mon, 11 Oct 2021 22:35:18 -0500 Subject: [PATCH 8/8] Update test/cli.test.js Co-authored-by: Jade Michael Thornton --- test/cli.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cli.test.js b/test/cli.test.js index 569c4254..3520f442 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -106,11 +106,11 @@ test('--proxy requires you to specify a protocol', (t) => { t.plan(1); const options = ['.', '--proxy', 'google.com']; - const ecstatic = startEcstatic(options); + const server = startServer(options); - tearDown(ecstatic, t); + tearDown(server, t); - ecstatic.on('exit', (code) => { + server.on('exit', (code) => { t.equal(code, 1); }); }); \ No newline at end of file