@fails-components/webtransport 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/lib/http2/browser/browser.d.ts.map +1 -1
  2. package/dist/lib/http2/browser/browserparser.d.ts +4 -3
  3. package/dist/lib/http2/browser/browserparser.d.ts.map +1 -1
  4. package/dist/lib/http2/node/capsuleparser.d.ts +3 -2
  5. package/dist/lib/http2/node/capsuleparser.d.ts.map +1 -1
  6. package/dist/lib/http2/node/client.d.ts.map +1 -1
  7. package/dist/lib/http2/node/server.d.ts +4 -4
  8. package/dist/lib/http2/node/server.d.ts.map +1 -1
  9. package/dist/lib/http2/node/websocketparser.d.ts +7 -6
  10. package/dist/lib/http2/node/websocketparser.d.ts.map +1 -1
  11. package/dist/lib/http2/parserbase.d.ts +16 -4
  12. package/dist/lib/http2/parserbase.d.ts.map +1 -1
  13. package/dist/lib/http2/parserbasehttp2.d.ts +9 -1
  14. package/dist/lib/http2/parserbasehttp2.d.ts.map +1 -1
  15. package/dist/lib/http2/session.d.ts.map +1 -1
  16. package/dist/lib/index.node.d.ts +1 -1
  17. package/dist/lib/index.node.d.ts.map +1 -1
  18. package/dist/lib/index.types.d.ts +1 -1
  19. package/dist/lib/index.types.d.ts.map +1 -1
  20. package/dist/lib/server.d.ts.map +1 -1
  21. package/dist/lib/session.d.ts +8 -4
  22. package/dist/lib/session.d.ts.map +1 -1
  23. package/dist/lib/types.d.ts +18 -6
  24. package/dist/lib/types.d.ts.map +1 -1
  25. package/dist/lib/webtransport.browser.d.ts.map +1 -1
  26. package/dist/lib/webtransport.node.d.ts +1 -0
  27. package/dist/lib/webtransport.node.d.ts.map +1 -1
  28. package/lib/http2/browser/browser.js +2 -1
  29. package/lib/http2/browser/browserparser.js +43 -7
  30. package/lib/http2/node/capsuleparser.js +41 -10
  31. package/lib/http2/node/client.js +28 -7
  32. package/lib/http2/node/server.js +117 -55
  33. package/lib/http2/node/websocketparser.js +42 -20
  34. package/lib/http2/parserbase.js +44 -7
  35. package/lib/http2/parserbasehttp2.js +15 -2
  36. package/lib/http2/session.js +1 -5
  37. package/lib/index.node.js +1 -1
  38. package/lib/index.types.js +1 -1
  39. package/lib/server.js +7 -4
  40. package/lib/session.js +5 -2
  41. package/lib/types.ts +19 -6
  42. package/lib/webtransport.browser.js +3 -2
  43. package/lib/webtransport.node.js +16 -5
  44. package/lib/webtransportbase.js +1 -1
  45. package/old_test/test.js +13 -1
  46. package/package.json +3 -2
  47. package/readme.md +4 -1
  48. package/test/bidirectional-streams.spec.js +31 -0
  49. package/test/datagrams.spec.js +12 -0
  50. package/test/fixtures/quiche.browser.js +2 -0
  51. package/test/fixtures/quiche.js +1 -0
  52. package/test/fixtures/read-stream.js +20 -7
  53. package/test/fixtures/reader-value.js +0 -5
  54. package/test/fixtures/server.js +70 -0
  55. package/test/session.spec.js +29 -3
  56. package/test/stream-limits.spec.js +12 -0
  57. package/test/unidirectional-streams.spec.js +12 -0
@@ -55,6 +55,32 @@ export async function createServer() {
55
55
 
56
56
  server.ready
57
57
  .then(async () => {
58
+ server.setRequestCallback(async (args) => {
59
+ const url = args.header[':path']
60
+ const [path] = url.split('?')
61
+
62
+ if (server.sessionController[path] == null) {
63
+ return {
64
+ ...args,
65
+ path,
66
+ status: 404
67
+ }
68
+ }
69
+
70
+ return {
71
+ ...args,
72
+ path,
73
+ userData: {
74
+ search: url.substring(path.length)
75
+ },
76
+ header: {
77
+ ...args.header,
78
+ ':path': path
79
+ },
80
+ status: 200
81
+ }
82
+ })
83
+
58
84
  // set up listeners for the different server paths used by the tests
59
85
  console.log('server ready')
60
86
  await Promise.all(
@@ -110,6 +136,30 @@ export async function createServer() {
110
136
  }
111
137
  },
112
138
 
139
+ // echo server, initiated by local
140
+ async () => {
141
+ for await (const session of getReaderStream(
142
+ server.sessionStream('/bidirectional_server_fin_send')
143
+ )) {
144
+ try {
145
+ // adapted from issue of achingbrain
146
+ const stream = await session.createBidirectionalStream()
147
+
148
+ const writer = stream.writable.getWriter()
149
+
150
+ await writer.ready
151
+
152
+ writer.write(Uint8Array.from([0, 1, 2, 3])).catch((err) => {
153
+ console.info('error writing to stream', err)
154
+ })
155
+
156
+ await writer.close()
157
+ } catch {
158
+ // in some tests the client closes the stream
159
+ }
160
+ }
161
+ },
162
+
113
163
  // echo datagrams, initiated by remote
114
164
  async () => {
115
165
  for await (const session of getReaderStream(
@@ -286,6 +336,26 @@ export async function createServer() {
286
336
  }
287
337
  },
288
338
 
339
+ // support user data
340
+ async () => {
341
+ for await (const session of getReaderStream(
342
+ server.sessionStream('/session_with_userdata')
343
+ )) {
344
+ try {
345
+ const stream = await session.createUnidirectionalStream()
346
+ await writeStream(stream, [
347
+ new TextEncoder().encode(JSON.stringify(session.userData))
348
+ ])
349
+ // session.close() // do not close it here, the stream is closed before a reader is attached on client side
350
+ } catch (err) {
351
+ session.close({
352
+ closeCode: 1,
353
+ reason: err.stack
354
+ })
355
+ }
356
+ }
357
+ },
358
+
289
359
  // send data over unidirectional stream, initiated by remote
290
360
  async () => {
291
361
  for await (const session of getReaderStream(
@@ -3,6 +3,9 @@
3
3
  import { readCertHash } from './fixtures/read-cert-hash.js'
4
4
  import WebTransport from './fixtures/webtransport.js'
5
5
  import { expect } from './fixtures/chai.js'
6
+ import { quicheLoaded } from './fixtures/quiche.js'
7
+ import { getReaderValue } from './fixtures/reader-value.js'
8
+ import { readStringFromStream } from './fixtures/read-stream.js'
6
9
 
7
10
  /**
8
11
  * @template T
@@ -38,6 +41,17 @@ describe('session', function () {
38
41
  // @ts-ignore
39
42
  delete wtOptions.serverCertificateHashes
40
43
 
44
+ // @ts-ignore
45
+ beforeEach(async () => {
46
+ if (
47
+ process.env.USE_HTTP2 !== 'true' &&
48
+ process.env.USE_PONYFILL !== 'true' &&
49
+ process.env.USE_POLYFILL !== 'true'
50
+ ) {
51
+ await quicheLoaded
52
+ }
53
+ })
54
+
41
55
  // @ts-ignore
42
56
  afterEach(async () => {
43
57
  if (client != null) {
@@ -68,10 +82,22 @@ describe('session', function () {
68
82
 
69
83
  const result = await client.closed
70
84
  expect(result).to.have.property('closeCode', 7)
71
- if (process.env.USE_HTTP2 !== 'true')
72
- // unsupported for http2
73
- expect(result).to.have.property('reason', 'this is the reason')
85
+ expect(result).to.have.property('reason', 'this is the reason')
86
+ })
87
+
88
+ it('should parse user data', async () => {
89
+ client = new WebTransport(
90
+ `${process.env.SERVER_URL}/session_with_userdata?foo=bar`,
91
+ wtOptions
92
+ )
93
+ await client.ready
94
+
95
+ const stream = await getReaderValue(client.incomingUnidirectionalStreams)
96
+ const string = await readStringFromStream(stream)
97
+ const userData = JSON.parse(string)
98
+ expect(userData).to.have.property('search', '?foo=bar')
74
99
  })
100
+
75
101
  if (browser === 'firefox') this.timeout(31000) // really firefox?
76
102
  it('should error when connecting to a server that does not exist', async () => {
77
103
  client = new WebTransport(`https://127.0.0.1:39821`, {
@@ -3,6 +3,7 @@
3
3
  import { readCertHash } from './fixtures/read-cert-hash.js'
4
4
  import WebTransport from './fixtures/webtransport.js'
5
5
  import { expect } from './fixtures/chai.js'
6
+ import { quicheLoaded } from './fixtures/quiche.js'
6
7
 
7
8
  /**
8
9
  * @template T
@@ -44,6 +45,17 @@ describe('streamlimits', function () {
44
45
  // @ts-ignore
45
46
  delete wtOptions.serverCertificateHashes
46
47
 
48
+ // @ts-ignore
49
+ beforeEach(async () => {
50
+ if (
51
+ process.env.USE_HTTP2 !== 'true' &&
52
+ process.env.USE_PONYFILL !== 'true' &&
53
+ process.env.USE_POLYFILL !== 'true'
54
+ ) {
55
+ await quicheLoaded
56
+ }
57
+ })
58
+
47
59
  // @ts-ignore
48
60
  afterEach(async () => {
49
61
  if (client != null) {
@@ -8,6 +8,7 @@ import { writeStream } from './fixtures/write-stream.js'
8
8
  import { readCertHash } from './fixtures/read-cert-hash.js'
9
9
  import * as ui8 from 'uint8arrays'
10
10
  import { KNOWN_BYTES, KNOWN_BYTES_LENGTH } from './fixtures/known-bytes.js'
11
+ import { quicheLoaded } from './fixtures/quiche.js'
11
12
 
12
13
  describe('unidirectional streams', function () {
13
14
  /** @type {import('../lib/dom').WebTransport | undefined} */
@@ -29,6 +30,17 @@ describe('unidirectional streams', function () {
29
30
  // @ts-ignore
30
31
  delete wtOptions.serverCertificateHashes
31
32
 
33
+ // @ts-ignore
34
+ beforeEach(async () => {
35
+ if (
36
+ process.env.USE_HTTP2 !== 'true' &&
37
+ process.env.USE_PONYFILL !== 'true' &&
38
+ process.env.USE_POLYFILL !== 'true'
39
+ ) {
40
+ await quicheLoaded
41
+ }
42
+ })
43
+
32
44
  // @ts-ignore
33
45
  afterEach(async () => {
34
46
  if (client != null) {