Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable create TLS server without initial context #183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 } });
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down