Skip to content

Commit

Permalink
Check if request is http2
Browse files Browse the repository at this point in the history
  • Loading branch information
sogaani committed Sep 17, 2018
1 parent b46f32d commit b4f3652
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function vhost (hostname, handle) {
*/

function hostnameof (req) {
var host = req.headers.host ? req.headers.host : req.headers[':authority']
var host = ishttp2(req) ? req.headers[':authority'] : req.headers.host

if (!host) {
return
Expand Down Expand Up @@ -137,7 +137,7 @@ function hostregexp (val) {
*/

function vhostof (req, regexp) {
var host = req.headers.host ? req.headers.host : req.headers[':authority']
var host = ishttp2(req) ? req.headers[':authority'] : req.headers.host
var hostname = hostnameof(req)

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

return obj
}

/**
* Check if a request is a http2 request.
*
* @param {Object} request
* @return {Boolean}
* @public
*/

function ishttp2 (req) {
return req.httpVersionMajor === 2
}

0 comments on commit b4f3652

Please sign in to comment.