Skip to content

Commit 088803d

Browse files
committed
Add http2 test
1 parent 3bed452 commit 088803d

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.travis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ node_js:
1010
- "5.12"
1111
- "6.12"
1212
- "7.10"
13-
- "8.9"
14-
- "9.3"
13+
- "8.11"
14+
- "10.7"
1515
sudo: false
1616
cache:
1717
directories:
@@ -23,6 +23,7 @@ before_install:
2323
# Setup Node.js version-specific dependencies
2424
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
2525
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)"
26+
- "test -z $(echo $HTTP2_TEST) || npm install --only=dev https://github.com/sogaani/supertest.git#http2"
2627

2728
# Update Node.js modules
2829
- "test ! -d node_modules || npm prune"
@@ -34,3 +35,10 @@ script:
3435
- "test -z $(npm -ps ls eslint ) || npm run-script lint"
3536
after_script:
3637
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
38+
39+
matrix:
40+
include:
41+
- node_js: "8.11"
42+
env: HTTP2_TEST=1
43+
- node_js: "10.7"
44+
env: HTTP2_TEST=1

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function vhost (hostname, handle) {
7474
*/
7575

7676
function hostnameof (req) {
77-
var host = req.host
77+
var host = req.headers.host ? req.headers.host : req.headers[':authority']
7878

7979
if (!host) {
8080
return
@@ -137,7 +137,7 @@ function hostregexp (val) {
137137
*/
138138

139139
function vhostof (req, regexp) {
140-
var host = req.host
140+
var host = req.headers.host ? req.headers.host : req.headers[':authority']
141141
var hostname = hostnameof(req)
142142

143143
if (!hostname) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"scripts": {
3232
"lint": "eslint --plugin markdown --ext js,md .",
3333
"test": "mocha --reporter spec --bail --check-leaks test/",
34+
"test-http2": "HTTP2_TEST=1 mocha --reporter spec --bail --check-leaks test/",
3435
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
3536
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
3637
}

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ var http = require('http')
44
var request = require('supertest')
55
var vhost = require('..')
66

7+
if (process.env.HTTP2_TEST) {
8+
request.http2 = true;
9+
http = require('http2')
10+
}
11+
712
describe('vhost(hostname, server)', function () {
813
it('should route by Host', function (done) {
914
var vhosts = []

0 commit comments

Comments
 (0)