From e3f988e399b7d58adce0c8f582a05f5d8149bfe1 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Fri, 3 Nov 2017 11:04:24 +0100 Subject: [PATCH] fix(server): avoid http2 experimental warning without http2 option --- lib/server.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index fa7e69dd4..77283159b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -30,14 +30,6 @@ var patchResponse = require('./response'); var http2; -// http2 module is not available < v8.4.0 (only with flag <= 8.8.0) -try { - http2 = require('http2'); - patchResponse(http2.Http2ServerResponse); - patchRequest(http2.Http2ServerRequest); - // eslint-disable-next-line no-empty -} catch (err) {} - patchResponse(http.ServerResponse); patchRequest(http.IncomingMessage); @@ -137,6 +129,17 @@ function Server(options) { this.spdy = true; this.server = spdy.createServer(options.spdy); } else if (options.http2) { + // http2 module is not available < v8.4.0 (only with flag <= 8.8.0) + // load http2 module here to avoid experimental warning in other cases + if (!http2) { + try { + http2 = require('http2'); + patchResponse(http2.Http2ServerResponse); + patchRequest(http2.Http2ServerRequest); + // eslint-disable-next-line no-empty + } catch (err) {} + } + assert( http2, 'http2 module is not available, ' +