Skip to content

Commit

Permalink
fix(sirv-cli): add graceful HTTP/1 compatibility (#74)
Browse files Browse the repository at this point in the history
* Allow http1 in the http2 server

* Add http1 test

* Set a different port in hopes of fixing the test

* Make the requested changes

* chore: shuffle lines

Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
  • Loading branch information
ArtskydJ and lukeed authored Jul 29, 2020
1 parent e7ef3f4 commit 4b419bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/sirv-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (dir, opts) {
return exit('HTTP/2 requires "key" and "cert" values');
}

opts.allowHTTP1 = true; // grace
opts.key = readFileSync(opts.key);
opts.cert = readFileSync(opts.cert);
if (opts.cacert) opts.cacert = readFileSync(opts.cacert);
Expand Down
15 changes: 15 additions & 0 deletions tests/sirv-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,19 @@ http2('should start a HTTP/2 server with valid args', async () => {
}
});

http2('should have backward compatibility with HTTP/1', async () => {
let pems = selfsigned.generate();
let key = await utils.write('foobar.key2', pems.private);
let cert = await utils.write('foobar.cert2', pems.cert);

let server = await utils.spawn('--http2', '--key', key, '--cert', cert);

try {
let res = await server.send('GET', '/blog', { rejectUnauthorized: false });
await utils.matches(res, 200, 'blog.html', 'utf8');
} finally {
server.close();
}
});

http2.run();

0 comments on commit 4b419bf

Please sign in to comment.