Skip to content

Commit 41bef65

Browse files
committed
Check if request is http2
1 parent 0fb0c22 commit 41bef65

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

index.js

Lines changed: 14 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.headers.host ? req.headers.host : req.headers[':authority']
77+
var host = ishttp2(req) ? req.headers[':authority'] : req.headers.host
7878

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

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

143143
if (!hostname) {
@@ -162,3 +162,15 @@ function vhostof (req, regexp) {
162162

163163
return obj
164164
}
165+
166+
/**
167+
* Check if a request is a http2 request.
168+
*
169+
* @param {Object} request
170+
* @return {Boolean}
171+
* @public
172+
*/
173+
174+
function ishttp2 (req) {
175+
return req.httpVersionMajor === 2
176+
}

0 commit comments

Comments
 (0)