fastify 5.3.3 → 5.5.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.
- package/.vscode/settings.json +15 -15
- package/LICENSE +1 -1
- package/README.md +2 -0
- package/SECURITY.md +158 -2
- package/build/build-validation.js +20 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +20 -5
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +5 -3
- package/docs/Reference/Hooks.md +16 -20
- package/docs/Reference/Lifecycle.md +2 -2
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +2 -2
- package/docs/Reference/Routes.md +7 -6
- package/docs/Reference/Server.md +341 -200
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +56 -4
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +4 -3
- package/fastify.js +47 -34
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +11 -0
- package/lib/handleRequest.js +13 -17
- package/lib/pluginOverride.js +3 -1
- package/lib/promise.js +23 -0
- package/lib/reply.js +24 -30
- package/lib/request.js +3 -10
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +19 -1
- package/package.json +14 -10
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +84 -128
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +90 -63
- package/test/buffer.test.js +22 -0
- package/test/build-certificate.js +1 -1
- package/test/case-insensitive.test.js +44 -65
- package/test/check.test.js +17 -21
- package/test/close-pipelining.test.js +24 -15
- package/test/constrained-routes.test.js +231 -0
- package/test/custom-http-server.test.js +7 -15
- package/test/custom-parser-async.test.js +17 -22
- package/test/custom-parser.0.test.js +267 -348
- package/test/custom-parser.1.test.js +141 -191
- package/test/custom-parser.2.test.js +34 -44
- package/test/custom-parser.3.test.js +56 -104
- package/test/custom-parser.4.test.js +106 -144
- package/test/custom-parser.5.test.js +56 -75
- package/test/custom-querystring-parser.test.js +51 -77
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +76 -259
- package/test/delete.test.js +101 -110
- package/test/diagnostics-channel/404.test.js +7 -15
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/async-request.test.js +8 -16
- package/test/diagnostics-channel/error-request.test.js +7 -15
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +9 -16
- package/test/diagnostics-channel/sync-request.test.js +9 -16
- package/test/fastify-instance.test.js +1 -1
- package/test/header-overflow.test.js +18 -29
- package/test/helper.js +139 -135
- package/test/hooks-async.test.js +259 -235
- package/test/hooks.test.js +951 -996
- package/test/http-methods/copy.test.js +14 -19
- package/test/http-methods/get.test.js +131 -143
- package/test/http-methods/head.test.js +53 -84
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcalendar.test.js +45 -72
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http-methods/unlock.test.js +5 -9
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +31 -28
- package/test/https/custom-https-server.test.js +9 -13
- package/test/https/https.test.js +56 -53
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +72 -65
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/issue-4959.test.js +12 -3
- package/test/listen.4.test.js +31 -43
- package/test/nullable-validation.test.js +33 -46
- package/test/output-validation.test.js +24 -26
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +108 -120
- package/test/plugin.3.test.js +50 -72
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +42 -63
- package/test/proto-poisoning.test.js +78 -97
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -146
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +117 -101
- package/test/route-prefix.test.js +194 -133
- package/test/route-shorthand.test.js +9 -27
- package/test/route.1.test.js +74 -131
- package/test/route.8.test.js +9 -17
- package/test/router-options.test.js +450 -0
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +254 -218
- package/test/server.test.js +143 -5
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +33 -50
- package/test/stream.4.test.js +18 -28
- package/test/stream.5.test.js +11 -19
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +13 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/request.test-d.ts +1 -0
- package/test/types/type-provider.test-d.ts +55 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +117 -59
- package/test/versioned-routes.test.js +39 -56
- package/types/errors.d.ts +11 -1
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('LOCK', { hasBody: true })
|
|
7
6
|
|
|
@@ -57,52 +56,53 @@ test('can be created - lock', t => {
|
|
|
57
56
|
})
|
|
58
57
|
|
|
59
58
|
test('lock test', async t => {
|
|
60
|
-
await fastify.listen({ port: 0 })
|
|
59
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
61
60
|
t.after(() => {
|
|
62
61
|
fastify.close()
|
|
63
62
|
})
|
|
64
63
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
65
64
|
// a specific content type parser
|
|
66
|
-
await t.test('request with body - lock', (t
|
|
65
|
+
await t.test('request with body - lock', async (t) => {
|
|
67
66
|
t.plan(3)
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
|
|
68
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
69
|
+
method: 'LOCK',
|
|
70
70
|
headers: { 'content-type': 'text/plain' },
|
|
71
|
-
body: bodySample
|
|
72
|
-
method: 'LOCK'
|
|
73
|
-
}, (err, response, body) => {
|
|
74
|
-
t.assert.ifError(err)
|
|
75
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
76
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
77
|
-
done()
|
|
71
|
+
body: bodySample
|
|
78
72
|
})
|
|
73
|
+
|
|
74
|
+
t.assert.ok(result.ok)
|
|
75
|
+
t.assert.strictEqual(result.status, 200)
|
|
76
|
+
const body = await result.text()
|
|
77
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
79
78
|
})
|
|
80
79
|
|
|
81
|
-
await t.test('request with body and no content type (415 error) - lock', (t
|
|
80
|
+
await t.test('request with body and no content type (415 error) - lock', async (t) => {
|
|
82
81
|
t.plan(3)
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
84
|
+
method: 'LOCK',
|
|
85
85
|
body: bodySample,
|
|
86
|
-
|
|
87
|
-
}, (err, response, body) => {
|
|
88
|
-
t.assert.ifError(err)
|
|
89
|
-
t.assert.strictEqual(response.statusCode, 415)
|
|
90
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
91
|
-
done()
|
|
86
|
+
headers: { 'content-type': undefined }
|
|
92
87
|
})
|
|
88
|
+
|
|
89
|
+
t.assert.ok(!result.ok)
|
|
90
|
+
t.assert.strictEqual(result.status, 415)
|
|
91
|
+
const body = await result.text()
|
|
92
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
await t.test('request without body - lock', (t
|
|
95
|
+
await t.test('request without body - lock', async (t) => {
|
|
96
96
|
t.plan(3)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}, (err, response, body) => {
|
|
102
|
-
t.assert.ifError(err)
|
|
103
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
104
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
105
|
-
done()
|
|
97
|
+
|
|
98
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
99
|
+
method: 'LOCK',
|
|
100
|
+
headers: { 'content-type': 'text/plain' }
|
|
106
101
|
})
|
|
102
|
+
|
|
103
|
+
t.assert.ok(result.ok)
|
|
104
|
+
t.assert.strictEqual(result.status, 200)
|
|
105
|
+
const body = await result.text()
|
|
106
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
107
107
|
})
|
|
108
108
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('MKCALENDAR', { hasBody: true })
|
|
7
6
|
|
|
@@ -78,93 +77,67 @@ test('can be created - mkcalendar', (t) => {
|
|
|
78
77
|
})
|
|
79
78
|
|
|
80
79
|
test('mkcalendar test', async t => {
|
|
81
|
-
await fastify.listen({ port: 0 })
|
|
80
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
82
81
|
t.after(() => {
|
|
83
82
|
fastify.close()
|
|
84
83
|
})
|
|
85
84
|
|
|
86
|
-
await t.test('request - mkcalendar',
|
|
87
|
-
t.plan(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
t.assert.ifError(err)
|
|
95
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
96
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
97
|
-
done()
|
|
98
|
-
}
|
|
99
|
-
)
|
|
85
|
+
await t.test('request - mkcalendar', async t => {
|
|
86
|
+
t.plan(2)
|
|
87
|
+
const result = await fetch(`${fastifyServer}/`, {
|
|
88
|
+
method: 'MKCALENDAR'
|
|
89
|
+
})
|
|
90
|
+
t.assert.strictEqual(result.status, 207)
|
|
91
|
+
const body = await result.text()
|
|
92
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
100
93
|
})
|
|
101
94
|
|
|
102
|
-
await t.test('request with other path - mkcalendar',
|
|
103
|
-
t.plan(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
t.assert.ifError(err)
|
|
111
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
112
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
113
|
-
done()
|
|
114
|
-
}
|
|
115
|
-
)
|
|
95
|
+
await t.test('request with other path - mkcalendar', async t => {
|
|
96
|
+
t.plan(2)
|
|
97
|
+
const result = await fetch(`${fastifyServer}/test`, {
|
|
98
|
+
method: 'MKCALENDAR'
|
|
99
|
+
})
|
|
100
|
+
t.assert.strictEqual(result.status, 207)
|
|
101
|
+
const body = await result.text()
|
|
102
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
116
103
|
})
|
|
117
104
|
|
|
118
105
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
119
106
|
// a specific content type parser
|
|
120
|
-
await t.test('request with body - mkcalendar',
|
|
107
|
+
await t.test('request with body - mkcalendar', async t => {
|
|
121
108
|
t.plan(3)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
132
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
133
|
-
done()
|
|
134
|
-
}
|
|
135
|
-
)
|
|
109
|
+
const result = await fetch(`${fastifyServer}/test`, {
|
|
110
|
+
method: 'MKCALENDAR',
|
|
111
|
+
headers: { 'content-type': 'text/plain' },
|
|
112
|
+
body: bodySample
|
|
113
|
+
})
|
|
114
|
+
t.assert.ok(result.ok)
|
|
115
|
+
t.assert.strictEqual(result.status, 207)
|
|
116
|
+
const body = await result.text()
|
|
117
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
136
118
|
})
|
|
137
119
|
|
|
138
|
-
await t.test('request with body and no content type (415 error) - mkcalendar',
|
|
120
|
+
await t.test('request with body and no content type (415 error) - mkcalendar', async t => {
|
|
139
121
|
t.plan(3)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
150
|
-
done()
|
|
151
|
-
}
|
|
152
|
-
)
|
|
122
|
+
const result = await fetch(`${fastifyServer}/test`, {
|
|
123
|
+
method: 'MKCALENDAR',
|
|
124
|
+
body: bodySample,
|
|
125
|
+
headers: { 'content-type': undefined }
|
|
126
|
+
})
|
|
127
|
+
t.assert.ok(!result.ok)
|
|
128
|
+
t.assert.strictEqual(result.status, 415)
|
|
129
|
+
const body = await result.text()
|
|
130
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
153
131
|
})
|
|
154
132
|
|
|
155
|
-
await t.test('request without body - mkcalendar',
|
|
133
|
+
await t.test('request without body - mkcalendar', async t => {
|
|
156
134
|
t.plan(3)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
165
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
166
|
-
done()
|
|
167
|
-
}
|
|
168
|
-
)
|
|
135
|
+
const result = await fetch(`${fastifyServer}/test`, {
|
|
136
|
+
method: 'MKCALENDAR'
|
|
137
|
+
})
|
|
138
|
+
t.assert.ok(result.ok)
|
|
139
|
+
t.assert.strictEqual(result.status, 207)
|
|
140
|
+
const body = await result.text()
|
|
141
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
169
142
|
})
|
|
170
143
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('MKCOL')
|
|
7
6
|
|
|
@@ -22,18 +21,15 @@ test('can be created - mkcol', t => {
|
|
|
22
21
|
})
|
|
23
22
|
|
|
24
23
|
test('mkcol test', async t => {
|
|
25
|
-
await fastify.listen({ port: 0 })
|
|
24
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
26
25
|
t.after(() => { fastify.close() })
|
|
27
26
|
|
|
28
|
-
await t.test('request - mkcol',
|
|
27
|
+
await t.test('request - mkcol', async t => {
|
|
29
28
|
t.plan(2)
|
|
30
|
-
|
|
31
|
-
url: `http://localhost:${fastify.server.address().port}/test/`,
|
|
29
|
+
const result = await fetch(`${fastifyServer}/test/`, {
|
|
32
30
|
method: 'MKCOL'
|
|
33
|
-
}, (err, response, body) => {
|
|
34
|
-
t.assert.ifError(err)
|
|
35
|
-
t.assert.strictEqual(response.statusCode, 201)
|
|
36
|
-
done()
|
|
37
31
|
})
|
|
32
|
+
t.assert.ok(result.ok)
|
|
33
|
+
t.assert.strictEqual(result.status, 201)
|
|
38
34
|
})
|
|
39
35
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('MOVE')
|
|
7
6
|
|
|
@@ -24,23 +23,20 @@ test('shorthand - move', t => {
|
|
|
24
23
|
}
|
|
25
24
|
})
|
|
26
25
|
test('move test', async t => {
|
|
27
|
-
await fastify.listen({ port: 0 })
|
|
26
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
28
27
|
|
|
29
28
|
t.after(() => { fastify.close() })
|
|
30
29
|
|
|
31
|
-
await t.test('request - move',
|
|
30
|
+
await t.test('request - move', async t => {
|
|
32
31
|
t.plan(3)
|
|
33
|
-
|
|
34
|
-
url: `http://localhost:${fastify.server.address().port}/test.txt`,
|
|
32
|
+
const result = await fetch(`${fastifyServer}/test.txt`, {
|
|
35
33
|
method: 'MOVE',
|
|
36
34
|
headers: {
|
|
37
35
|
Destination: '/test2.txt'
|
|
38
36
|
}
|
|
39
|
-
}, (err, response, body) => {
|
|
40
|
-
t.assert.ifError(err)
|
|
41
|
-
t.assert.strictEqual(response.statusCode, 201)
|
|
42
|
-
t.assert.strictEqual(response.headers.location, '/test2.txt')
|
|
43
|
-
done()
|
|
44
37
|
})
|
|
38
|
+
t.assert.ok(result.ok)
|
|
39
|
+
t.assert.strictEqual(result.status, 201)
|
|
40
|
+
t.assert.strictEqual(result.headers.get('location'), '/test2.txt')
|
|
45
41
|
})
|
|
46
42
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('PROPFIND', { hasBody: true })
|
|
7
6
|
|
|
@@ -74,73 +73,64 @@ test('propfind test', async t => {
|
|
|
74
73
|
fastify.close()
|
|
75
74
|
})
|
|
76
75
|
|
|
77
|
-
await t.test('request - propfind',
|
|
76
|
+
await t.test('request - propfind', async t => {
|
|
78
77
|
t.plan(3)
|
|
79
|
-
|
|
80
|
-
url: `http://localhost:${fastify.server.address().port}/`,
|
|
78
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/`, {
|
|
81
79
|
method: 'PROPFIND'
|
|
82
|
-
}, (err, response, body) => {
|
|
83
|
-
t.assert.ifError(err)
|
|
84
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
85
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
86
|
-
done()
|
|
87
80
|
})
|
|
81
|
+
t.assert.ok(result.ok)
|
|
82
|
+
t.assert.strictEqual(result.status, 207)
|
|
83
|
+
const body = await result.text()
|
|
84
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
88
85
|
})
|
|
89
86
|
|
|
90
|
-
await t.test('request with other path - propfind',
|
|
87
|
+
await t.test('request with other path - propfind', async t => {
|
|
91
88
|
t.plan(3)
|
|
92
|
-
|
|
93
|
-
url: `http://localhost:${fastify.server.address().port}/test`,
|
|
89
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
94
90
|
method: 'PROPFIND'
|
|
95
|
-
}, (err, response, body) => {
|
|
96
|
-
t.assert.ifError(err)
|
|
97
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
98
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
99
|
-
done()
|
|
100
91
|
})
|
|
92
|
+
t.assert.ok(result.ok)
|
|
93
|
+
t.assert.strictEqual(result.status, 207)
|
|
94
|
+
const body = await result.text()
|
|
95
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
101
96
|
})
|
|
102
97
|
|
|
103
98
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
104
99
|
// a specific content type parser
|
|
105
|
-
await t.test('request with body - propfind',
|
|
100
|
+
await t.test('request with body - propfind', async t => {
|
|
106
101
|
t.plan(3)
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
103
|
+
method: 'PROPFIND',
|
|
109
104
|
headers: { 'content-type': 'text/plain' },
|
|
110
|
-
body: bodySample
|
|
111
|
-
method: 'PROPFIND'
|
|
112
|
-
}, (err, response, body) => {
|
|
113
|
-
t.assert.ifError(err)
|
|
114
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
115
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
116
|
-
done()
|
|
105
|
+
body: bodySample
|
|
117
106
|
})
|
|
107
|
+
t.assert.ok(result.ok)
|
|
108
|
+
t.assert.strictEqual(result.status, 207)
|
|
109
|
+
const body = await result.text()
|
|
110
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
118
111
|
})
|
|
119
112
|
|
|
120
|
-
await t.test('request with body and no content type (415 error) - propfind',
|
|
113
|
+
await t.test('request with body and no content type (415 error) - propfind', async t => {
|
|
121
114
|
t.plan(3)
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
116
|
+
method: 'PROPFIND',
|
|
124
117
|
body: bodySample,
|
|
125
|
-
|
|
126
|
-
}, (err, response, body) => {
|
|
127
|
-
t.assert.ifError(err)
|
|
128
|
-
t.assert.strictEqual(response.statusCode, 415)
|
|
129
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
130
|
-
done()
|
|
118
|
+
headers: { 'content-type': '' }
|
|
131
119
|
})
|
|
120
|
+
t.assert.ok(!result.ok)
|
|
121
|
+
t.assert.strictEqual(result.status, 415)
|
|
122
|
+
const body = await result.text()
|
|
123
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
132
124
|
})
|
|
133
125
|
|
|
134
|
-
await t.test('request without body - propfind',
|
|
126
|
+
await t.test('request without body - propfind', async t => {
|
|
135
127
|
t.plan(3)
|
|
136
|
-
|
|
137
|
-
url: `http://localhost:${fastify.server.address().port}/test`,
|
|
128
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
138
129
|
method: 'PROPFIND'
|
|
139
|
-
}, (err, response, body) => {
|
|
140
|
-
t.assert.ifError(err)
|
|
141
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
142
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
143
|
-
done()
|
|
144
130
|
})
|
|
131
|
+
t.assert.ok(result.ok)
|
|
132
|
+
t.assert.strictEqual(result.status, 207)
|
|
133
|
+
const body = await result.text()
|
|
134
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
145
135
|
})
|
|
146
136
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('PROPPATCH', { hasBody: true })
|
|
7
6
|
|
|
@@ -62,50 +61,45 @@ test('shorthand - proppatch', t => {
|
|
|
62
61
|
})
|
|
63
62
|
|
|
64
63
|
test('proppatch test', async t => {
|
|
65
|
-
await fastify.listen({ port: 0 })
|
|
64
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
66
65
|
|
|
67
66
|
t.after(() => { fastify.close() })
|
|
68
67
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
69
68
|
// a specific content type parser
|
|
70
|
-
await t.test('request with body - proppatch',
|
|
69
|
+
await t.test('request with body - proppatch', async t => {
|
|
71
70
|
t.plan(3)
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
72
|
+
method: 'PROPPATCH',
|
|
74
73
|
headers: { 'content-type': 'text/plain' },
|
|
75
|
-
body: bodySample
|
|
76
|
-
method: 'PROPPATCH'
|
|
77
|
-
}, (err, response, body) => {
|
|
78
|
-
t.assert.ifError(err)
|
|
79
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
80
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
81
|
-
done()
|
|
74
|
+
body: bodySample
|
|
82
75
|
})
|
|
76
|
+
t.assert.ok(result.ok)
|
|
77
|
+
t.assert.strictEqual(result.status, 207)
|
|
78
|
+
const body = await result.text()
|
|
79
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
83
80
|
})
|
|
84
81
|
|
|
85
|
-
await t.test('request with body and no content type (415 error) - proppatch',
|
|
82
|
+
await t.test('request with body and no content type (415 error) - proppatch', async t => {
|
|
86
83
|
t.plan(3)
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
85
|
+
method: 'PROPPATCH',
|
|
89
86
|
body: bodySample,
|
|
90
|
-
|
|
91
|
-
}, (err, response, body) => {
|
|
92
|
-
t.assert.ifError(err)
|
|
93
|
-
t.assert.strictEqual(response.statusCode, 415)
|
|
94
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
95
|
-
done()
|
|
87
|
+
headers: { 'content-type': undefined }
|
|
96
88
|
})
|
|
89
|
+
t.assert.ok(!result.ok)
|
|
90
|
+
t.assert.strictEqual(result.status, 415)
|
|
91
|
+
const body = await result.text()
|
|
92
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
97
93
|
})
|
|
98
94
|
|
|
99
|
-
await t.test('request without body - proppatch',
|
|
95
|
+
await t.test('request without body - proppatch', async t => {
|
|
100
96
|
t.plan(3)
|
|
101
|
-
|
|
102
|
-
url: `http://localhost:${fastify.server.address().port}/test/a.txt`,
|
|
97
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
103
98
|
method: 'PROPPATCH'
|
|
104
|
-
}, (err, response, body) => {
|
|
105
|
-
t.assert.ifError(err)
|
|
106
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
107
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
108
|
-
done()
|
|
109
99
|
})
|
|
100
|
+
t.assert.ok(result.ok)
|
|
101
|
+
t.assert.strictEqual(result.status, 207)
|
|
102
|
+
const body = await result.text()
|
|
103
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
110
104
|
})
|
|
111
105
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('REPORT', { hasBody: true })
|
|
7
6
|
|
|
@@ -80,88 +79,64 @@ test('report test', async t => {
|
|
|
80
79
|
fastify.close()
|
|
81
80
|
})
|
|
82
81
|
|
|
83
|
-
await t.test('request - report', (t
|
|
82
|
+
await t.test('request - report', async (t) => {
|
|
84
83
|
t.plan(3)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
93
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
94
|
-
done()
|
|
95
|
-
}
|
|
96
|
-
)
|
|
84
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/`, {
|
|
85
|
+
method: 'REPORT'
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
t.assert.ok(result.ok)
|
|
89
|
+
t.assert.strictEqual(result.status, 207)
|
|
90
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
97
91
|
})
|
|
98
92
|
|
|
99
|
-
await t.test('request with other path - report', (t
|
|
93
|
+
await t.test('request with other path - report', async (t) => {
|
|
100
94
|
t.plan(3)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
109
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
110
|
-
done()
|
|
111
|
-
}
|
|
112
|
-
)
|
|
95
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
96
|
+
method: 'REPORT'
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
t.assert.ok(result.ok)
|
|
100
|
+
t.assert.strictEqual(result.status, 207)
|
|
101
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
113
102
|
})
|
|
114
103
|
|
|
115
104
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
116
105
|
// a specific content type parser
|
|
117
|
-
await t.test('request with body - report', (t
|
|
106
|
+
await t.test('request with body - report', async (t) => {
|
|
118
107
|
t.plan(3)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
129
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
130
|
-
done()
|
|
131
|
-
}
|
|
132
|
-
)
|
|
108
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
109
|
+
method: 'REPORT',
|
|
110
|
+
headers: { 'content-type': 'text/plain' },
|
|
111
|
+
body: bodySample
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
t.assert.ok(result.ok)
|
|
115
|
+
t.assert.strictEqual(result.status, 207)
|
|
116
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
133
117
|
})
|
|
134
118
|
|
|
135
|
-
await t.test('request with body and no content type (415 error) - report', (t
|
|
119
|
+
await t.test('request with body and no content type (415 error) - report', async (t) => {
|
|
136
120
|
t.plan(3)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
147
|
-
done()
|
|
148
|
-
}
|
|
149
|
-
)
|
|
121
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
122
|
+
method: 'REPORT',
|
|
123
|
+
body: bodySample,
|
|
124
|
+
headers: { 'content-type': '' }
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
t.assert.ok(!result.ok)
|
|
128
|
+
t.assert.strictEqual(result.status, 415)
|
|
129
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
150
130
|
})
|
|
151
131
|
|
|
152
|
-
await t.test('request without body - report', (t
|
|
132
|
+
await t.test('request without body - report', async (t) => {
|
|
153
133
|
t.plan(3)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
162
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
163
|
-
done()
|
|
164
|
-
}
|
|
165
|
-
)
|
|
134
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
135
|
+
method: 'REPORT'
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
t.assert.ok(result.ok)
|
|
139
|
+
t.assert.strictEqual(result.status, 207)
|
|
140
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
166
141
|
})
|
|
167
142
|
})
|