Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,53 +1,52 @@
'use strict'
const { test, skip } = require('tap')
const { describe, test } = require('node:test')
const Fastify = require('..')
const { connect } = require('node:net')
const { once } = require('node:events')
const dns = require('node:dns').promises
async function setup () {
describe('upgrade to both servers', async () => {
const localAddresses = await dns.lookup('localhost', { all: true })
if (localAddresses.length === 1) {
skip('requires both IPv4 and IPv6')
return
}
const skip = localAddresses.length === 1 && 'requires both IPv4 and IPv6'
test('upgrade to both servers', async t => {
await test('upgrade IPv4 and IPv6', { skip }, async t => {
t.plan(2)
const app = Fastify()
app.server.on('upgrade', (req, socket, head) => {
t.pass(`upgrade event ${JSON.stringify(socket.address())}`)
const fastify = Fastify()
fastify.server.on('upgrade', (req, socket, head) => {
t.assert.ok(`upgrade event ${JSON.stringify(socket.address())}`)
socket.end()
})
app.get('/', (req, res) => {
fastify.get('/', (req, res) => {
res.send()
})
await app.listen()
t.teardown(app.close.bind(app))
await fastify.listen()
t.after(() => fastify.close())
{
const client = connect(app.server.address().port, '127.0.0.1')
client.write('GET / HTTP/1.1\r\n')
client.write('Upgrade: websocket\r\n')
client.write('Connection: Upgrade\r\n')
client.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
client.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
client.write('Sec-WebSocket-Version: 13\r\n\r\n')
client.write('\r\n\r\n')
await once(client, 'close')
const clientIPv4 = connect(fastify.server.address().port, '127.0.0.1')
clientIPv4.write('GET / HTTP/1.1\r\n')
clientIPv4.write('Upgrade: websocket\r\n')
clientIPv4.write('Connection: Upgrade\r\n')
clientIPv4.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
clientIPv4.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
clientIPv4.write('Sec-WebSocket-Version: 13\r\n\r\n')
clientIPv4.write('\r\n\r\n')
await once(clientIPv4, 'close')
}
{
const client = connect(app.server.address().port, '::1')
client.write('GET / HTTP/1.1\r\n')
client.write('Upgrade: websocket\r\n')
client.write('Connection: Upgrade\r\n')
client.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
client.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
client.write('Sec-WebSocket-Version: 13\r\n\r\n')
await once(client, 'close')
const clientIPv6 = connect(fastify.server.address().port, '::1')
clientIPv6.write('GET / HTTP/1.1\r\n')
clientIPv6.write('Upgrade: websocket\r\n')
clientIPv6.write('Connection: Upgrade\r\n')
clientIPv6.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
clientIPv6.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
clientIPv6.write('Sec-WebSocket-Version: 13\r\n\r\n')
await once(clientIPv6, 'close')
}
})
}
setup()
})