aboutsummaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-12-29 09:44:08 -0800
committerJames M Snell <jasnell@gmail.com>2018-01-03 08:45:58 -0800
commitce22d6f9178507c7a41b04ac4097b9ea902049e3 (patch)
tree4b82a06cff1bb3fde32e4f101cd254111d8f9bf4 /test/parallel
parentf51067a85d64b77f2eae2e099092209156d6e602 (diff)
downloadandroid-node-v8-ce22d6f9178507c7a41b04ac4097b9ea902049e3.tar.gz
android-node-v8-ce22d6f9178507c7a41b04ac4097b9ea902049e3.tar.bz2
android-node-v8-ce22d6f9178507c7a41b04ac4097b9ea902049e3.zip
http2: add altsvc support
Add support for sending and receiving ALTSVC frames. PR-URL: https://github.com/nodejs/node/pull/17917 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-http2-altsvc.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/test/parallel/test-http2-altsvc.js b/test/parallel/test-http2-altsvc.js
new file mode 100644
index 0000000000..9fd9a9fc27
--- /dev/null
+++ b/test/parallel/test-http2-altsvc.js
@@ -0,0 +1,126 @@
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const assert = require('assert');
+const http2 = require('http2');
+const { URL } = require('url');
+const Countdown = require('../common/countdown');
+
+const server = http2.createServer();
+server.on('stream', common.mustCall((stream) => {
+ stream.session.altsvc('h2=":8000"', stream.id);
+ stream.respond();
+ stream.end('ok');
+}));
+server.on('session', common.mustCall((session) => {
+ // Origin may be specified by string, URL object, or object with an
+ // origin property. For string and URL object, origin is guaranteed
+ // to be an ASCII serialized origin. For object with an origin
+ // property, it is up to the user to ensure proper serialization.
+ session.altsvc('h2=":8000"', 'https://example.org:8111/this');
+ session.altsvc('h2=":8000"', new URL('https://example.org:8111/this'));
+ session.altsvc('h2=":8000"', { origin: 'https://example.org:8111' });
+
+ // Won't error, but won't send anything because the stream does not exist
+ session.altsvc('h2=":8000"', 3);
+
+ // Will error because the numeric stream id is out of valid range
+ [0, -1, 1.1, 0xFFFFFFFF + 1, Infinity, -Infinity].forEach((i) => {
+ common.expectsError(
+ () => session.altsvc('h2=":8000"', i),
+ {
+ code: 'ERR_OUT_OF_RANGE',
+ type: RangeError
+ }
+ );
+ });
+
+ // First argument must be a string
+ [0, {}, [], null, Infinity].forEach((i) => {
+ common.expectsError(
+ () => session.altsvc(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ });
+
+ ['\u0001', 'h2="\uff20"', '👀'].forEach((i) => {
+ common.expectsError(
+ () => session.altsvc(i),
+ {
+ code: 'ERR_INVALID_CHAR',
+ type: TypeError
+ }
+ );
+ });
+
+ [{}, [], true].forEach((i) => {
+ common.expectsError(
+ () => session.altsvc('clear', i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ });
+
+ [
+ 'abc:',
+ new URL('abc:'),
+ { origin: 'null' },
+ { origin: '' }
+ ].forEach((i) => {
+ common.expectsError(
+ () => session.altsvc('h2=":8000', i),
+ {
+ code: 'ERR_HTTP2_ALTSVC_INVALID_ORIGIN',
+ type: TypeError
+ }
+ );
+ });
+
+ // arguments + origin are too long for an ALTSVC frame
+ common.expectsError(
+ () => {
+ session.altsvc('h2=":8000"',
+ `http://example.${'a'.repeat(17000)}.org:8000`);
+ },
+ {
+ code: 'ERR_HTTP2_ALTSVC_LENGTH',
+ type: TypeError
+ }
+ );
+}));
+
+server.listen(0, common.mustCall(() => {
+ const client = http2.connect(`http://localhost:${server.address().port}`);
+
+ const countdown = new Countdown(4, () => {
+ client.close();
+ server.close();
+ });
+
+ client.on('altsvc', common.mustCall((alt, origin, stream) => {
+ assert.strictEqual(alt, 'h2=":8000"');
+ switch (stream) {
+ case 0:
+ assert.strictEqual(origin, 'https://example.org:8111');
+ break;
+ case 1:
+ assert.strictEqual(origin, '');
+ break;
+ default:
+ assert.fail('should not happen');
+ }
+ countdown.dec();
+ }, 4));
+
+ const req = client.request();
+ req.resume();
+ req.on('close', common.mustCall());
+}));