@fastify/reply-from 9.0.0 → 9.0.1
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/.taprc +1 -1
- package/lib/request.js +11 -1
- package/package.json +2 -2
- package/test/http-timeout.test.js +82 -0
- package/test/{http2-target-multi-crash.js → http2-target-multi-crash.test.js} +3 -1
- package/test/{http2-timeout.js → http2-timeout.test.js} +32 -1
- package/test/http-timeout.js +0 -57
- /package/test/{async-route-handler.js → async-route-handler.test.js} +0 -0
- /package/test/{base-get.js → base-get.test.js} +0 -0
- /package/test/{base-path.js → base-path.test.js} +0 -0
- /package/test/{base-querystring.js → base-querystring.test.js} +0 -0
- /package/test/{build-url.js → build-url.test.js} +0 -0
- /package/test/{core-with-path-in-base.js → core-with-path-in-base.test.js} +0 -0
- /package/test/{custom-undici-instance.js → custom-undici-instance.test.js} +0 -0
- /package/test/{disable-request-logging.js → disable-request-logging.test.js} +0 -0
- /package/test/{fastify-multipart-incompatibility.js → fastify-multipart-incompatibility.test.js} +0 -0
- /package/test/{full-get.js → full-get-test.test.js} +0 -0
- /package/test/{full-https-get.js → full-https-get.test.js} +0 -0
- /package/test/{full-post-extended-content-type.js → full-post-extended-content-type.test.js} +0 -0
- /package/test/{full-post-http2.js → full-post-http2.test.js} +0 -0
- /package/test/{full-post-stream-core.js → full-post-stream-core.test.js} +0 -0
- /package/test/{full-post-stream.js → full-post-stream.test.js} +0 -0
- /package/test/{full-post.js → full-post.test.js} +0 -0
- /package/test/{full-querystring-rewrite-option-complex.js → full-querystring-rewrite-option-complex.test.js} +0 -0
- /package/test/{full-querystring-rewrite-option-function.js → full-querystring-rewrite-option-function.test.js} +0 -0
- /package/test/{full-querystring-rewrite-option.js → full-querystring-rewrite-option.test.js} +0 -0
- /package/test/{full-querystring-rewrite-string.js → full-querystring-rewrite-string.test.js} +0 -0
- /package/test/{full-querystring-rewrite.js → full-querystring-rewrite.test.js} +0 -0
- /package/test/{full-querystring.js → full-querystring.test.js} +0 -0
- /package/test/{full-rewrite-body-content-type.js → full-rewrite-body-content-type.test.js} +0 -0
- /package/test/{full-rewrite-body-http.js → full-rewrite-body-http.test.js} +0 -0
- /package/test/{full-rewrite-body-to-empty-string.js → full-rewrite-body-to-empty-string.test.js} +0 -0
- /package/test/{full-rewrite-body-to-null.js → full-rewrite-body-to-null.test.js} +0 -0
- /package/test/{full-rewrite-body.js → full-rewrite-body.test.js} +0 -0
- /package/test/{get-upstream-cache.js → get-upstream-cache.test.js} +0 -0
- /package/test/{get-upstream-http.js → get-upstream-http.test.js} +0 -0
- /package/test/{get-upstream-type.js → get-upstream-type.test.js} +0 -0
- /package/test/{get-upstream-undici.js → get-upstream-undici.test.js} +0 -0
- /package/test/{get-with-body.js → get-with-body.test.js} +0 -0
- /package/test/{head-with-body.js → head-with-body.test.js} +0 -0
- /package/test/{host-header.js → host-header.test.js} +0 -0
- /package/test/{http-agents.js → http-agents.test.js} +0 -0
- /package/test/{http-global-agent.js → http-global-agent.test.js} +0 -0
- /package/test/{http-http2.js → http-http2.test.js} +0 -0
- /package/test/{http-invalid-target.js → http-invalid-target.test.js} +0 -0
- /package/test/{http-retry.js → http-retry.test.js} +0 -0
- /package/test/{http2-http2.js → http2-http2.test.js} +0 -0
- /package/test/{http2-https.js → http2-https.test.js} +0 -0
- /package/test/{http2-invalid-base.js → http2-invalid-base.test.js} +0 -0
- /package/test/{http2-invalid-target.js → http2-invalid-target.test.js} +0 -0
- /package/test/{http2-target-crash.js → http2-target-crash.test.js} +0 -0
- /package/test/{http2-unix-socket.js → http2-unix-socket.test.js} +0 -0
- /package/test/{https-agents.js → https-agents.test.js} +0 -0
- /package/test/{https-global-agent.js → https-global-agent.test.js} +0 -0
- /package/test/{modifyCoreObjects-false.js → modifyCoreObjects-false.test.js} +0 -0
- /package/test/{no-body-opts-with-get.js → no-body-opts-with-get.test.js} +0 -0
- /package/test/{no-body-opts-with-head.js → no-body-opts-with-head.test.js} +0 -0
- /package/test/{no-stream-body-option.js → no-stream-body-option.test.js} +0 -0
- /package/test/{on-error.js → on-error.test.js} +0 -0
- /package/test/{onResponse.js → onResponse.test.js} +0 -0
- /package/test/{padded-body.js → padded-body.test.js} +0 -0
- /package/test/{post-formbody.js → post-formbody.test.js} +0 -0
- /package/test/{post-plain-text.js → post-plain-text.test.js} +0 -0
- /package/test/{post-with-custom-encoded-contenttype.js → post-with-custom-encoded-contenttype.test.js} +0 -0
- /package/test/{post-with-octet-stream.js → post-with-octet-stream.test.js} +0 -0
- /package/test/{retry-on-503.js → retry-on-503.test.js} +0 -0
- /package/test/{rewrite-headers-type.js → rewrite-headers-type.test.js} +0 -0
- /package/test/{rewrite-headers.js → rewrite-headers.test.js} +0 -0
- /package/test/{rewrite-request-headers-type.js → rewrite-request-headers-type.test.js} +0 -0
- /package/test/{rewrite-request-headers.js → rewrite-request-headers.test.js} +0 -0
- /package/test/{transform-body.js → transform-body.test.js} +0 -0
- /package/test/{undici-agent.js → undici-agent.test.js} +0 -0
- /package/test/{undici-body.js → undici-body.test.js} +0 -0
- /package/test/{undici-chaining.js → undici-chaining.test.js} +0 -0
- /package/test/{undici-global-agent.js → undici-global-agent.test.js} +0 -0
- /package/test/{undici-options.js → undici-options.test.js} +0 -0
- /package/test/{undici-retry.js → undici-retry.test.js} +0 -0
- /package/test/{undici-timeout-body-partial.js → undici-timeout-body-partial.test.js} +0 -0
- /package/test/{undici-timeout-body.js → undici-timeout-body.test.js} +0 -0
- /package/test/{undici-timeout.js → undici-timeout.test.js} +0 -0
- /package/test/{undici-with-path-in-base.js → undici-with-path-in-base.test.js} +0 -0
- /package/test/{undici.js → undici.test.js} +0 -0
- /package/test/{unexpected-error.js → unexpected-error.test.js} +0 -0
- /package/test/{unix-http-undici-from.js → unix-http-undici-from.test.js} +0 -0
- /package/test/{unix-http-undici.js → unix-http-undici.test.js} +0 -0
- /package/test/{unix-http.js → unix-http.test.js} +0 -0
- /package/test/{unix-https-undici.js → unix-https-undici.test.js} +0 -0
- /package/test/{unix-https.js → unix-https.test.js} +0 -0
- /package/test/{utils-filter-pseudo-headers.js → utils-filter-pseudo-headers.test.js} +0 -0
package/.taprc
CHANGED
package/lib/request.js
CHANGED
|
@@ -112,6 +112,10 @@ function buildRequest (opts) {
|
|
|
112
112
|
})
|
|
113
113
|
req.on('error', done)
|
|
114
114
|
req.on('response', res => {
|
|
115
|
+
// remove timeout for sse connections
|
|
116
|
+
if (res.headers['content-type'] === 'text/event-stream') {
|
|
117
|
+
req.setTimeout(0)
|
|
118
|
+
}
|
|
115
119
|
done(null, { statusCode: res.statusCode, headers: res.headers, stream: res })
|
|
116
120
|
})
|
|
117
121
|
req.once('timeout', () => {
|
|
@@ -210,6 +214,12 @@ function buildRequest (opts) {
|
|
|
210
214
|
if (err) done(err)
|
|
211
215
|
})
|
|
212
216
|
req.on('response', headers => {
|
|
217
|
+
// remove timeout for sse connections
|
|
218
|
+
if (headers['content-type'] === 'text/event-stream') {
|
|
219
|
+
req.setTimeout(0)
|
|
220
|
+
http2Client.setTimeout(0)
|
|
221
|
+
}
|
|
222
|
+
|
|
213
223
|
const statusCode = headers[':status']
|
|
214
224
|
done(null, { statusCode, headers, stream: req })
|
|
215
225
|
})
|
|
@@ -250,7 +260,7 @@ function getHttp2Opts (opts) {
|
|
|
250
260
|
http2Opts.sessionOptions = http2Opts.sessionOptions || {}
|
|
251
261
|
|
|
252
262
|
if (!http2Opts.sessionTimeout) {
|
|
253
|
-
http2Opts.sessionTimeout = opts.sessionTimeout ||
|
|
263
|
+
http2Opts.sessionTimeout = opts.sessionTimeout || 60000
|
|
254
264
|
}
|
|
255
265
|
if (!http2Opts.requestTimeout) {
|
|
256
266
|
http2Opts.requestTimeout = 10000
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/reply-from",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "forward your HTTP request to another server, for fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"split2": "^4.1.0",
|
|
47
47
|
"standard": "^17.0.0",
|
|
48
48
|
"tap": "^16.2.0",
|
|
49
|
-
"tsd": "^0.
|
|
49
|
+
"tsd": "^0.26.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@fastify/error": "^3.0.0",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const Fastify = require('fastify')
|
|
5
|
+
const From = require('..')
|
|
6
|
+
const got = require('got')
|
|
7
|
+
const FakeTimers = require('@sinonjs/fake-timers')
|
|
8
|
+
|
|
9
|
+
const clock = FakeTimers.createClock()
|
|
10
|
+
|
|
11
|
+
test('http request timeout', async (t) => {
|
|
12
|
+
t.autoend(false)
|
|
13
|
+
|
|
14
|
+
const target = Fastify()
|
|
15
|
+
t.teardown(target.close.bind(target))
|
|
16
|
+
|
|
17
|
+
target.get('/', (request, reply) => {
|
|
18
|
+
t.pass('request arrives')
|
|
19
|
+
|
|
20
|
+
clock.setTimeout(() => {
|
|
21
|
+
reply.status(200).send('hello world')
|
|
22
|
+
t.end()
|
|
23
|
+
}, 200)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
await target.listen({ port: 0 })
|
|
27
|
+
|
|
28
|
+
const instance = Fastify()
|
|
29
|
+
t.teardown(instance.close.bind(instance))
|
|
30
|
+
|
|
31
|
+
instance.register(From, { http: { requestOptions: { timeout: 100 } } })
|
|
32
|
+
|
|
33
|
+
instance.get('/', (request, reply) => {
|
|
34
|
+
reply.from(`http://localhost:${target.server.address().port}/`)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
await instance.listen({ port: 0 })
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
await got.get(`http://localhost:${instance.server.address().port}/`, { retry: 0 })
|
|
41
|
+
} catch (err) {
|
|
42
|
+
t.equal(err.response.statusCode, 504)
|
|
43
|
+
t.match(err.response.headers['content-type'], /application\/json/)
|
|
44
|
+
t.same(JSON.parse(err.response.body), {
|
|
45
|
+
statusCode: 504,
|
|
46
|
+
code: 'FST_REPLY_FROM_GATEWAY_TIMEOUT',
|
|
47
|
+
error: 'Gateway Timeout',
|
|
48
|
+
message: 'Gateway Timeout'
|
|
49
|
+
})
|
|
50
|
+
clock.tick(200)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
t.fail()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('http sse removes timeout test', async (t) => {
|
|
58
|
+
const target = Fastify()
|
|
59
|
+
t.teardown(target.close.bind(target))
|
|
60
|
+
|
|
61
|
+
target.get('/', (request, reply) => {
|
|
62
|
+
t.pass('request arrives')
|
|
63
|
+
|
|
64
|
+
reply.header('content-type', 'text/event-stream').status(200).send('hello world')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
await target.listen({ port: 0 })
|
|
68
|
+
|
|
69
|
+
const instance = Fastify()
|
|
70
|
+
t.teardown(instance.close.bind(instance))
|
|
71
|
+
|
|
72
|
+
instance.register(From, { http: { requestOptions: { timeout: 100 } } })
|
|
73
|
+
|
|
74
|
+
instance.get('/', (request, reply) => {
|
|
75
|
+
reply.from(`http://localhost:${target.server.address().port}/`)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
await instance.listen({ port: 0 })
|
|
79
|
+
|
|
80
|
+
const { statusCode } = await got.get(`http://localhost:${instance.server.address().port}/`, { retry: 0 })
|
|
81
|
+
t.equal(statusCode, 200)
|
|
82
|
+
})
|
|
@@ -20,7 +20,7 @@ test('http2 request timeout', async (t) => {
|
|
|
20
20
|
|
|
21
21
|
instance.register(From, {
|
|
22
22
|
base: `http://localhost:${target.server.address().port}`,
|
|
23
|
-
http2: { requestTimeout: 100 }
|
|
23
|
+
http2: { requestTimeout: 100, sessionTimeout: 6000 }
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
instance.get('/', (request, reply) => {
|
|
@@ -92,3 +92,34 @@ test('http2 session timeout', async (t) => {
|
|
|
92
92
|
|
|
93
93
|
t.fail()
|
|
94
94
|
})
|
|
95
|
+
|
|
96
|
+
test('http2 sse removes request and session timeout test', async (t) => {
|
|
97
|
+
const target = Fastify({ http2: true, sessionTimeout: 0 })
|
|
98
|
+
|
|
99
|
+
target.get('/', (request, reply) => {
|
|
100
|
+
t.pass('request arrives')
|
|
101
|
+
|
|
102
|
+
reply.status(200).header('content-type', 'text/event-stream').send('hello world')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
await target.listen({ port: 0 })
|
|
106
|
+
|
|
107
|
+
const instance = Fastify()
|
|
108
|
+
|
|
109
|
+
instance.register(From, {
|
|
110
|
+
base: `http://localhost:${target.server.address().port}`,
|
|
111
|
+
http2: { sessionTimeout: 100 }
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
instance.get('/', (request, reply) => {
|
|
115
|
+
reply.from(`http://localhost:${target.server.address().port}/`)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
await instance.listen({ port: 0 })
|
|
119
|
+
|
|
120
|
+
t.teardown(instance.close.bind(instance))
|
|
121
|
+
t.teardown(target.close.bind(target))
|
|
122
|
+
|
|
123
|
+
const { statusCode } = await got.get(`http://localhost:${instance.server.address().port}/`, { retry: 0 })
|
|
124
|
+
t.equal(statusCode, 200)
|
|
125
|
+
})
|
package/test/http-timeout.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const t = require('tap')
|
|
4
|
-
const Fastify = require('fastify')
|
|
5
|
-
const From = require('..')
|
|
6
|
-
const got = require('got')
|
|
7
|
-
const FakeTimers = require('@sinonjs/fake-timers')
|
|
8
|
-
|
|
9
|
-
const clock = FakeTimers.createClock()
|
|
10
|
-
|
|
11
|
-
t.autoend(false)
|
|
12
|
-
|
|
13
|
-
const target = Fastify()
|
|
14
|
-
t.teardown(target.close.bind(target))
|
|
15
|
-
|
|
16
|
-
target.get('/', (request, reply) => {
|
|
17
|
-
t.pass('request arrives')
|
|
18
|
-
|
|
19
|
-
clock.setTimeout(() => {
|
|
20
|
-
reply.status(200).send('hello world')
|
|
21
|
-
t.end()
|
|
22
|
-
}, 200)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
async function main () {
|
|
26
|
-
await target.listen({ port: 0 })
|
|
27
|
-
|
|
28
|
-
const instance = Fastify()
|
|
29
|
-
t.teardown(instance.close.bind(instance))
|
|
30
|
-
|
|
31
|
-
instance.register(From, { http: { requestOptions: { timeout: 100 } } })
|
|
32
|
-
|
|
33
|
-
instance.get('/', (request, reply) => {
|
|
34
|
-
reply.from(`http://localhost:${target.server.address().port}/`)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
await instance.listen({ port: 0 })
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
await got.get(`http://localhost:${instance.server.address().port}/`, { retry: 0 })
|
|
41
|
-
} catch (err) {
|
|
42
|
-
t.equal(err.response.statusCode, 504)
|
|
43
|
-
t.match(err.response.headers['content-type'], /application\/json/)
|
|
44
|
-
t.same(JSON.parse(err.response.body), {
|
|
45
|
-
statusCode: 504,
|
|
46
|
-
code: 'FST_REPLY_FROM_GATEWAY_TIMEOUT',
|
|
47
|
-
error: 'Gateway Timeout',
|
|
48
|
-
message: 'Gateway Timeout'
|
|
49
|
-
})
|
|
50
|
-
clock.tick(200)
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
t.fail()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/test/{fastify-multipart-incompatibility.js → fastify-multipart-incompatibility.test.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/test/{full-post-extended-content-type.js → full-post-extended-content-type.test.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/test/{full-querystring-rewrite-option.js → full-querystring-rewrite-option.test.js}
RENAMED
|
File without changes
|
/package/test/{full-querystring-rewrite-string.js → full-querystring-rewrite-string.test.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/test/{full-rewrite-body-to-empty-string.js → full-rewrite-body-to-empty-string.test.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|