diff --git a/lib/http.js b/lib/http.js index 7c6d753f..c67c3563 100644 --- a/lib/http.js +++ b/lib/http.js @@ -440,8 +440,15 @@ function Server(options) { var start = this._start.bind(this); var fallback = this._fallback.bind(this); + // HTTP2 over plain TCP + if (options.plain) { + this._log.info('Creating HTTP/2 server over plain TCP'); + this._mode = 'plain'; + this._server = net.createServer(start); + } + // HTTP2 over TLS (using NPN or ALPN) - if ((options.key && options.cert) || options.pfx) { + else { this._log.info('Creating HTTP/2 server over TLS'); this._mode = 'tls'; options.ALPNProtocols = supportedProtocols; @@ -467,19 +474,6 @@ function Server(options) { forwardEvent('listening', this._server, this); } - // HTTP2 over plain TCP - else if (options.plain) { - this._log.info('Creating HTTP/2 server over plain TCP'); - this._mode = 'plain'; - this._server = net.createServer(start); - } - - // HTTP/2 with HTTP/1.1 upgrade - else { - this._log.error('Trying to create HTTP/2 server with Upgrade from HTTP/1.1'); - throw new Error('HTTP1.1 -> HTTP2 upgrade is not yet supported. Please provide TLS keys.'); - } - this._server.on('close', this.emit.bind(this, 'close')); } Server.prototype = Object.create(EventEmitter.prototype, { constructor: { value: Server } }); @@ -611,10 +605,8 @@ function createServerRaw(options, requestListener) { function createServerTLS(options, requestListener) { if (typeof options === 'function') { - throw new Error('options are required!'); - } - if (!options.pfx && !(options.key && options.cert)) { - throw new Error('options.pfx or options.key and options.cert are required!'); + requestListener = options; + options = {}; } options.plain = false; diff --git a/test/http.js b/test/http.js index efd0f393..fc054748 100644 --- a/test/http.js +++ b/test/http.js @@ -30,13 +30,13 @@ describe('http.js', function() { }); describe('Server', function() { describe('new Server(options)', function() { - it('should throw if called without \'plain\' or TLS options', function() { + it('should not throw if called without \'plain\' or TLS options', function() { expect(function() { - new http2.Server(); - }).to.throw(Error); + new http2.Server().close(); + }).not.to.throw(Error); expect(function() { - http2.createServer(util.noop); - }).to.throw(Error); + http2.createServer(util.noop).close(); + }).not.to.throw(Error); }); }); describe('method `listen()`', function () {