fastify 5.2.1 → 5.2.2
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.
- package/.vscode/settings.json +22 -0
- package/LICENSE +1 -1
- package/PROJECT_CHARTER.md +7 -7
- package/README.md +24 -25
- package/SPONSORS.md +2 -0
- package/docs/Guides/Benchmarking.md +4 -4
- package/docs/Guides/Database.md +1 -1
- package/docs/Guides/Delay-Accepting-Requests.md +10 -10
- package/docs/Guides/Ecosystem.md +5 -1
- package/docs/Guides/Fluent-Schema.md +1 -1
- package/docs/Guides/Getting-Started.md +9 -5
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +1 -1
- package/docs/Guides/Migration-Guide-V5.md +12 -2
- package/docs/Guides/Plugins-Guide.md +6 -6
- package/docs/Guides/Serverless.md +14 -48
- package/docs/Guides/Style-Guide.md +2 -2
- package/docs/Guides/Testing.md +2 -2
- package/docs/Guides/Write-Plugin.md +2 -3
- package/docs/Reference/ContentTypeParser.md +58 -78
- package/docs/Reference/Decorators.md +50 -60
- package/docs/Reference/Encapsulation.md +28 -33
- package/docs/Reference/Errors.md +50 -53
- package/docs/Reference/HTTP2.md +7 -7
- package/docs/Reference/Hooks.md +31 -30
- package/docs/Reference/LTS.md +10 -15
- package/docs/Reference/Lifecycle.md +19 -24
- package/docs/Reference/Logging.md +59 -56
- package/docs/Reference/Middleware.md +19 -19
- package/docs/Reference/Plugins.md +55 -71
- package/docs/Reference/Principles.md +25 -30
- package/docs/Reference/Reply.md +11 -10
- package/docs/Reference/Request.md +89 -98
- package/docs/Reference/Routes.md +108 -128
- package/docs/Reference/Server.md +18 -16
- package/docs/Reference/Type-Providers.md +19 -21
- package/docs/Reference/TypeScript.md +1 -18
- package/docs/Reference/Validation-and-Serialization.md +134 -159
- package/docs/Reference/Warnings.md +22 -25
- package/fastify.js +1 -1
- package/lib/contentTypeParser.js +7 -8
- package/lib/error-handler.js +14 -12
- package/lib/headRoute.js +4 -2
- package/lib/pluginUtils.js +4 -2
- package/lib/server.js +5 -0
- package/lib/validation.js +1 -1
- package/lib/warnings.js +9 -0
- package/lib/wrapThenable.js +8 -1
- package/package.json +10 -10
- package/test/build/error-serializer.test.js +2 -1
- package/test/bundler/esbuild/package.json +1 -1
- package/test/close.test.js +125 -108
- package/test/custom-parser-async.test.js +34 -36
- package/test/genReqId.test.js +125 -174
- package/test/has-route.test.js +1 -3
- package/test/internals/content-type-parser.test.js +1 -1
- package/test/issue-4959.test.js +84 -0
- package/test/listen.1.test.js +37 -34
- package/test/listen.2.test.js +47 -40
- package/test/listen.3.test.js +28 -32
- package/test/listen.4.test.js +61 -45
- package/test/listen.5.test.js +23 -0
- package/test/register.test.js +55 -50
- package/test/request-error.test.js +114 -94
- package/test/route-shorthand.test.js +36 -32
- package/test/server.test.js +0 -175
- package/test/stream.5.test.js +35 -33
- package/test/throw.test.js +87 -91
- package/test/toolkit.js +32 -0
- package/test/trust-proxy.test.js +23 -23
- package/test/types/instance.test-d.ts +1 -0
- package/test/upgrade.test.js +32 -30
- package/types/instance.d.ts +4 -0
package/test/upgrade.test.js
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { describe, test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
const { connect } = require('node:net')
|
|
6
6
|
const { once } = require('node:events')
|
|
7
7
|
const dns = require('node:dns').promises
|
|
8
8
|
|
|
9
|
-
async
|
|
9
|
+
describe('upgrade to both servers', async t => {
|
|
10
10
|
const localAddresses = await dns.lookup('localhost', { all: true })
|
|
11
11
|
if (localAddresses.length === 1) {
|
|
12
|
-
skip('requires both IPv4 and IPv6')
|
|
12
|
+
t.skip('requires both IPv4 and IPv6')
|
|
13
13
|
return
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
test('upgrade
|
|
16
|
+
await test('upgrade IPv4 and IPv6', async t => {
|
|
17
17
|
t.plan(2)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
|
|
19
|
+
const fastify = Fastify()
|
|
20
|
+
fastify.server.on('upgrade', (req, socket, head) => {
|
|
21
|
+
t.assert.ok(`upgrade event ${JSON.stringify(socket.address())}`)
|
|
21
22
|
socket.end()
|
|
22
23
|
})
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
fastify.get('/', (req, res) => {
|
|
26
|
+
res.send()
|
|
24
27
|
})
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
await fastify.listen()
|
|
30
|
+
t.after(() => fastify.close())
|
|
27
31
|
|
|
28
32
|
{
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await once(
|
|
33
|
+
const clientIPv4 = connect(fastify.server.address().port, '127.0.0.1')
|
|
34
|
+
clientIPv4.write('GET / HTTP/1.1\r\n')
|
|
35
|
+
clientIPv4.write('Upgrade: websocket\r\n')
|
|
36
|
+
clientIPv4.write('Connection: Upgrade\r\n')
|
|
37
|
+
clientIPv4.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
|
|
38
|
+
clientIPv4.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
|
|
39
|
+
clientIPv4.write('Sec-WebSocket-Version: 13\r\n\r\n')
|
|
40
|
+
clientIPv4.write('\r\n\r\n')
|
|
41
|
+
await once(clientIPv4, 'close')
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
{
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
await once(
|
|
45
|
+
const clientIPv6 = connect(fastify.server.address().port, '::1')
|
|
46
|
+
clientIPv6.write('GET / HTTP/1.1\r\n')
|
|
47
|
+
clientIPv6.write('Upgrade: websocket\r\n')
|
|
48
|
+
clientIPv6.write('Connection: Upgrade\r\n')
|
|
49
|
+
clientIPv6.write('Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n')
|
|
50
|
+
clientIPv6.write('Sec-WebSocket-Protocol: com.xxx.service.v1\r\n')
|
|
51
|
+
clientIPv6.write('Sec-WebSocket-Version: 13\r\n\r\n')
|
|
52
|
+
await once(clientIPv6, 'close')
|
|
49
53
|
}
|
|
50
54
|
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setup()
|
|
55
|
+
})
|
package/types/instance.d.ts
CHANGED
|
@@ -548,6 +548,10 @@ export interface FastifyInstance<
|
|
|
548
548
|
* Remove all content type parsers, including the default ones
|
|
549
549
|
*/
|
|
550
550
|
removeAllContentTypeParsers: removeAllContentTypeParsers
|
|
551
|
+
/**
|
|
552
|
+
* Returns an array of strings containing the list of supported HTTP methods
|
|
553
|
+
*/
|
|
554
|
+
supportedMethods: string[]
|
|
551
555
|
/**
|
|
552
556
|
* Add a non-standard HTTP method
|
|
553
557
|
*
|