From 3bed452af41c74cff3a1f05d150f875c71f00583 Mon Sep 17 00:00:00 2001 From: sogaani Date: Sun, 29 Jul 2018 04:34:14 +0900 Subject: [PATCH 1/3] support http2 --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 480fd19..c9989be 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,7 @@ function vhost (hostname, handle) { */ function hostnameof (req) { - var host = req.headers.host + var host = req.host if (!host) { return @@ -137,7 +137,7 @@ function hostregexp (val) { */ function vhostof (req, regexp) { - var host = req.headers.host + var host = req.host var hostname = hostnameof(req) if (!hostname) { From 088803d8d166396e14479a333f3cf5ef706ac29e Mon Sep 17 00:00:00 2001 From: sogaani Date: Mon, 30 Jul 2018 22:44:44 +0900 Subject: [PATCH 2/3] Add http2 test --- .travis.yml | 12 ++++++++++-- index.js | 4 ++-- package.json | 1 + test/test.js | 5 +++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c98f746..2801330 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ node_js: - "5.12" - "6.12" - "7.10" - - "8.9" - - "9.3" + - "8.11" + - "10.7" sudo: false cache: directories: @@ -23,6 +23,7 @@ before_install: # Setup Node.js version-specific dependencies - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)" + - "test -z $(echo $HTTP2_TEST) || npm install --only=dev https://github.com/sogaani/supertest.git#http2" # Update Node.js modules - "test ! -d node_modules || npm prune" @@ -34,3 +35,10 @@ script: - "test -z $(npm -ps ls eslint ) || npm run-script lint" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" + +matrix: + include: + - node_js: "8.11" + env: HTTP2_TEST=1 + - node_js: "10.7" + env: HTTP2_TEST=1 diff --git a/index.js b/index.js index c9989be..b7c08a2 100644 --- a/index.js +++ b/index.js @@ -74,7 +74,7 @@ function vhost (hostname, handle) { */ function hostnameof (req) { - var host = req.host + var host = req.headers.host ? req.headers.host : req.headers[':authority'] if (!host) { return @@ -137,7 +137,7 @@ function hostregexp (val) { */ function vhostof (req, regexp) { - var host = req.host + var host = req.headers.host ? req.headers.host : req.headers[':authority'] var hostname = hostnameof(req) if (!hostname) { diff --git a/package.json b/package.json index a137963..248b30f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "scripts": { "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", + "test-http2": "HTTP2_TEST=1 mocha --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" } diff --git a/test/test.js b/test/test.js index 7d377b2..3c26f36 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,11 @@ var http = require('http') var request = require('supertest') var vhost = require('..') +if (process.env.HTTP2_TEST) { + request.http2 = true; + http = require('http2') +} + describe('vhost(hostname, server)', function () { it('should route by Host', function (done) { var vhosts = [] From 0fb0c2221f6c3d4269cfcd34c4f05c9bd376284b Mon Sep 17 00:00:00 2001 From: sogaani Date: Wed, 1 Aug 2018 20:31:21 +0900 Subject: [PATCH 3/3] Lint --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 3c26f36..aca3b0c 100644 --- a/test/test.js +++ b/test/test.js @@ -5,7 +5,7 @@ var request = require('supertest') var vhost = require('..') if (process.env.HTTP2_TEST) { - request.http2 = true; + request.http2 = true http = require('http2') }