Skip to content
Merged
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
6 changes: 6 additions & 0 deletions test/http2-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ test('Agent should support H2 connection', async t => {
})
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

const response = await client.request({
origin: `https://localhost:${server.address().port}`,
path: '/',
Expand Down
12 changes: 12 additions & 0 deletions test/http2-alpn.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ test('Should upgrade to HTTP/2 when HTTPS/1 is available for GET', async (t) =>
// close the client on teardown
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

// make an undici request using where it wants http/2
const response = await client.request({
path: '/',
Expand Down Expand Up @@ -211,6 +217,12 @@ test('Should upgrade to HTTP/2 when HTTPS/1 is available for POST', async (t) =>
// close the client on teardown
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

// make an undici request using where it wants http/2
const response = await client.request({
path: '/',
Expand Down
54 changes: 54 additions & 0 deletions test/http2-dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ test('Dispatcher#Stream', async t => {
})
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

await client.stream(
{ path: '/', opaque: { bufs }, method: 'POST', body: expectedBody },
({ statusCode, headers, opaque: { bufs } }) => {
Expand Down Expand Up @@ -99,6 +105,12 @@ test('Dispatcher#Pipeline', async t => {
})
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

pipeline(
new Readable({
read () {
Expand Down Expand Up @@ -159,6 +171,12 @@ test('Dispatcher#Connect', async t => {
})
after(() => forward.close())

forward.on('disconnect', () => {
if (!forward.closed && !forward.destroyed) {
t.fail('unexpected disconnect')
}
})

try {
const response = await forward.request({
path: '/',
Expand Down Expand Up @@ -206,6 +224,12 @@ test('Dispatcher#Connect', async t => {
after(() => proxy.close())
after(() => server.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

const { statusCode, headers, socket } = await client.connect({ path: '/', headers: { 'x-my-header': 'foo' } })
t.strictEqual(statusCode, 200)
t.strictEqual(headers['x-my-header'], 'foo')
Expand Down Expand Up @@ -589,6 +613,12 @@ test('Should handle h2 request without body', async t => {
})
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

const response = await client.request({
path: '/',
method: 'POST',
Expand Down Expand Up @@ -635,6 +665,12 @@ test('Should clear h2 request stream references before completing a response', a
})
after(() => client.close())

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

let requestStreamIdSymbol = null
let requestStreamSymbol = null
let requestStreamCleanupSymbol = null
Expand Down Expand Up @@ -925,6 +961,12 @@ test('Should send http2 PING frames', async t => {
server.close()
})

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

client.dispatch({
path: '/',
method: 'PUT',
Expand Down Expand Up @@ -996,6 +1038,12 @@ test('Should not send http2 PING frames if interval === 0', async t => {
server.close()
})

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

client.dispatch({
path: '/',
method: 'PUT',
Expand Down Expand Up @@ -1068,6 +1116,12 @@ test('Should not send http2 PING frames after connection is closed', async t =>
server.close()
})

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

client.dispatch({
path: '/',
method: 'PUT',
Expand Down
24 changes: 17 additions & 7 deletions test/http2-trailers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const assert = require('node:assert')
const { test } = require('node:test')
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { createSecureServer } = require('node:http2')
const { once } = require('node:events')

Expand All @@ -10,10 +10,12 @@ const pem = require('@metcoder95/https-pem')
const { Client } = require('..')

test('Should handle http2 trailers', async t => {
t = tspl(t, { plan: 4 })

const server = createSecureServer(pem)
let client = null

t.after(async () => {
after(async () => {
await client?.close()
await new Promise(resolve => server.close(resolve))
})
Expand Down Expand Up @@ -44,14 +46,22 @@ test('Should handle http2 trailers', async t => {
allowH2: true
})

client.on('disconnect', () => {
if (!client.closed && !client.destroyed) {
t.fail('unexpected disconnect')
}
})

const { statusCode, headers, body, trailers } = await client.request({
path: '/',
method: 'PUT',
body: 'hello'
})

assert.strictEqual(statusCode, 200)
assert.strictEqual(headers['content-type'], 'text/plain; charset=utf-8')
assert.strictEqual(await body.text(), 'hello h2!')
assert.deepStrictEqual(trailers, { 'x-trailer': 'hello' })
t.strictEqual(statusCode, 200)
t.strictEqual(headers['content-type'], 'text/plain; charset=utf-8')
t.strictEqual(await body.text(), 'hello h2!')
t.deepStrictEqual(trailers, { 'x-trailer': 'hello' })

await t.completed
})
Loading