Skip to content

Commit

Permalink
fix(server): avoid http2 exprimental warning without http2 option
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Nov 3, 2017
1 parent 04b37dc commit 051a93f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/server.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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, ' +
Expand Down

0 comments on commit 051a93f

Please sign in to comment.