@fastify/reply-from
Advanced tools
Comparing version 9.8.0 to 10.0.0-pre.fv5.1
@@ -41,2 +41,3 @@ 'use strict' | ||
base, | ||
sessionTimeout: opts.sessionTimeout, | ||
undici: opts.undici, | ||
@@ -204,3 +205,3 @@ globalAgent: opts.globalAgent, | ||
if (onResponse) { | ||
onResponse(this.request, this, res.stream) | ||
onResponse(this.request, this, res) | ||
} else { | ||
@@ -271,5 +272,3 @@ this.send(res.stream) | ||
function isFastifyMultipartRegistered (fastify) { | ||
// TODO: remove fastify.hasContentTypeParser('multipart') in next major | ||
// It is used to be compatible with @fastify/multipart@<=7.3.0 | ||
return (fastify.hasContentTypeParser('multipart') || fastify.hasContentTypeParser('multipart/form-data')) && fastify.hasRequestDecorator('multipart') | ||
return fastify.hasContentTypeParser('multipart/form-data') | ||
} | ||
@@ -276,0 +275,0 @@ |
@@ -275,6 +275,6 @@ 'use strict' | ||
if (!http2Opts.sessionTimeout) { | ||
if (http2Opts.sessionTimeout === undefined) { | ||
http2Opts.sessionTimeout = opts.sessionTimeout || 60000 | ||
} | ||
if (!http2Opts.requestTimeout) { | ||
if (http2Opts.requestTimeout === undefined) { | ||
http2Opts.requestTimeout = 10000 | ||
@@ -281,0 +281,0 @@ } |
{ | ||
"name": "@fastify/reply-from", | ||
"version": "9.8.0", | ||
"version": "10.0.0-pre.fv5.1", | ||
"description": "forward your HTTP request to another server, for fastify", | ||
@@ -33,31 +33,31 @@ "main": "index.js", | ||
"@fastify/formbody": "^7.4.0", | ||
"@fastify/multipart": "^7.4.0", | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@sinonjs/fake-timers": "^11.0.0", | ||
"@types/node": "^20.1.4", | ||
"@types/tap": "^15.0.7", | ||
"fastify": "^4.0.2", | ||
"@fastify/multipart": "^8.2.0", | ||
"@fastify/pre-commit": "^2.1.0", | ||
"@sinonjs/fake-timers": "^11.2.2", | ||
"@types/node": "^20.11.30", | ||
"@types/tap": "^15.0.11", | ||
"fastify": "^4.26.2", | ||
"form-data": "^4.0.0", | ||
"got": "^11.8.2", | ||
"got": "^11.8.6", | ||
"h2url": "^0.2.0", | ||
"msgpack5": "^6.0.1", | ||
"nock": "^13.2.6", | ||
"msgpack5": "^6.0.2", | ||
"nock": "^13.5.4", | ||
"proxy": "^2.1.1", | ||
"proxyquire": "^2.1.3", | ||
"semver": "^7.5.1", | ||
"semver": "^7.6.0", | ||
"simple-get": "^4.0.1", | ||
"snazzy": "^9.0.0", | ||
"split2": "^4.1.0", | ||
"standard": "^17.0.0", | ||
"tap": "^16.2.0", | ||
"split2": "^4.2.0", | ||
"standard": "^17.1.0", | ||
"tap": "^18.7.2", | ||
"tsd": "^0.31.0" | ||
}, | ||
"dependencies": { | ||
"@fastify/error": "^3.0.0", | ||
"@fastify/error": "^3.4.1", | ||
"end-of-stream": "^1.4.4", | ||
"fast-content-type-parse": "^1.1.0", | ||
"fast-querystring": "^1.0.0", | ||
"fastify-plugin": "^4.0.0", | ||
"fast-querystring": "^1.1.2", | ||
"fastify-plugin": "^4.5.1", | ||
"toad-cache": "^3.7.0", | ||
"undici": "^5.19.1" | ||
"undici": "^6.11.1" | ||
}, | ||
@@ -64,0 +64,0 @@ "pre-commit": [ |
@@ -347,6 +347,7 @@ # @fastify/reply-from | ||
#### `onResponse(request, reply, res)` | ||
#### `onResponse(request, reply, response)` | ||
Called when a HTTP response is received from the source. | ||
The default behavior is `reply.send(res)`, which will be disabled if the | ||
Called when a HTTP response is received from the source. Passed the original source `request`, the in-progress reply to the source as `reply`, and the ongoing `response` from the upstream server. | ||
The default behavior is `reply.send(response.stream)`, which will be disabled if the | ||
option is specified. | ||
@@ -366,2 +367,4 @@ | ||
**Note**: `onResponse` is called after headers have already been sent. If you want to modify response headers, use the `rewriteHeaders` hook. | ||
#### `onError(reply, error)` | ||
@@ -490,4 +493,4 @@ | ||
- `requestTimeout` & `sessionTimeout` for `http2` set by default. | ||
- The default value for `requestTimeout` is 10 seconds (`10000`). | ||
- The default value for `sessionTimeout` is 60 seconds (`60000`). | ||
- The default value for `requestTimeout` is 10 seconds (`10000`), a value of 0 disables the timeout. | ||
- The default value for `sessionTimeout` is 60 seconds (`60000`), a value of 0 disables the timeout. | ||
@@ -494,0 +497,0 @@ When a timeout happens, [`504 Gateway Timeout`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) |
@@ -50,2 +50,4 @@ 'use strict' | ||
t.same(body, { hello: 'world' }) | ||
instance.close() | ||
target.close() | ||
}) |
@@ -49,2 +49,4 @@ 'use strict' | ||
t.same(body, { hello: 'world' }) | ||
instance.close() | ||
target.close() | ||
}) |
@@ -54,4 +54,6 @@ 'use strict' | ||
t.equal(data.toString(), 'hello world') | ||
instance.close() | ||
target.close() | ||
}) | ||
}) | ||
}) |
@@ -46,2 +46,4 @@ 'use strict' | ||
t.same(JSON.parse(err.response.body), { hello: 'world' }) | ||
instance.close() | ||
target.close() | ||
return | ||
@@ -48,0 +50,0 @@ } |
@@ -12,4 +12,2 @@ 'use strict' | ||
test('http request timeout', async (t) => { | ||
t.autoend(false) | ||
const target = Fastify() | ||
@@ -16,0 +14,0 @@ t.teardown(target.close.bind(target)) |
@@ -57,2 +57,4 @@ 'use strict' | ||
t.same(JSON.parse(body), { hello: 'world' }) | ||
instance.close() | ||
target.close() | ||
}) |
@@ -10,5 +10,5 @@ 'use strict' | ||
await t.rejects(instance.register(From, { | ||
await t.rejects(async () => instance.register(From, { | ||
http2: { requestTimeout: 100 } | ||
}), new Error('Option base is required when http2 is true')) | ||
}) |
@@ -125,2 +125,4 @@ 'use strict' | ||
t.equal(statusCode, 200) | ||
instance.close() | ||
target.close() | ||
}) |
@@ -12,3 +12,3 @@ 'use strict' | ||
await t.rejects(instance.register(From, { | ||
await t.rejects(async () => instance.register(From, { | ||
base: 'unix+http://localhost:1337', | ||
@@ -15,0 +15,0 @@ http2: { requestTimeout: 100 } |
@@ -11,17 +11,15 @@ 'use strict' | ||
t.autoend(false) | ||
t.test('on-error', async (t) => { | ||
const target = Fastify() | ||
t.teardown(target.close.bind(target)) | ||
const target = Fastify() | ||
t.teardown(target.close.bind(target)) | ||
target.get('/', (request, reply) => { | ||
t.pass('request arrives') | ||
target.get('/', (request, reply) => { | ||
t.pass('request arrives') | ||
clock.setTimeout(() => { | ||
reply.status(200).send('hello world') | ||
t.end() | ||
}, 1000) | ||
}) | ||
clock.setTimeout(() => { | ||
reply.status(200).send('hello world') | ||
t.end() | ||
}, 1000) | ||
}) | ||
async function main () { | ||
await target.listen({ port: 0 }) | ||
@@ -67,4 +65,2 @@ | ||
t.fail() | ||
} | ||
main() | ||
}) |
@@ -12,3 +12,3 @@ 'use strict' | ||
t.plan(8) | ||
t.plan(9) | ||
t.teardown(instance.close.bind(instance)) | ||
@@ -26,4 +26,5 @@ | ||
onResponse: (request2, reply, res) => { | ||
t.equal(res.statusCode, 200) | ||
t.equal(request1.raw, request2.raw) | ||
reply.send(res) | ||
reply.send(res.stream) | ||
} | ||
@@ -30,0 +31,0 @@ }) |
@@ -29,3 +29,3 @@ 'use strict' | ||
reply.send( | ||
res.pipe( | ||
res.stream.pipe( | ||
new Transform({ | ||
@@ -32,0 +32,0 @@ transform: function (chunk, enc, cb) { |
@@ -34,3 +34,3 @@ 'use strict' | ||
undici: proxyquire('undici', { | ||
'./lib/agent': proxyquire('undici/lib/agent.js', { | ||
'./lib/dispatcher/agent': proxyquire('undici/lib/dispatcher/agent.js', { | ||
'./pool': class Pool extends undici.Pool { | ||
@@ -37,0 +37,0 @@ constructor (url, options) { |
@@ -10,14 +10,12 @@ 'use strict' | ||
t.autoend(false) | ||
t.test('undici connect timeout', async (t) => { | ||
// never connect | ||
net.connect = function (options) { | ||
return new net.Socket(options) | ||
} | ||
net.connect = function (options) { | ||
return new net.Socket(options) | ||
} | ||
const target = http.createServer((req, res) => { | ||
t.fail('target never called') | ||
}) | ||
const target = http.createServer((req, res) => { | ||
t.fail('target never called') | ||
}) | ||
async function main () { | ||
t.plan(2) | ||
@@ -57,4 +55,2 @@ await target.listen({ port: 0 }) | ||
t.fail() | ||
} | ||
main() | ||
}) |
@@ -59,2 +59,4 @@ 'use strict' | ||
resolve() | ||
instance.close() | ||
target.close() | ||
}) | ||
@@ -61,0 +63,0 @@ }) |
@@ -12,19 +12,17 @@ 'use strict' | ||
t.autoend(false) | ||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
req.on('data', () => undefined) | ||
req.on('end', () => { | ||
res.writeHead(200) | ||
res.flushHeaders() | ||
res.write('test') | ||
clock.setTimeout(() => { | ||
res.end() | ||
t.end() | ||
}, 1000) | ||
t.test('undici body timeout', async (t) => { | ||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
req.on('data', () => undefined) | ||
req.on('end', () => { | ||
res.writeHead(200) | ||
res.flushHeaders() | ||
res.write('test') | ||
clock.setTimeout(() => { | ||
res.end() | ||
t.end() | ||
}, 1000) | ||
}) | ||
}) | ||
}) | ||
async function main () { | ||
await target.listen({ port: 0 }) | ||
@@ -59,4 +57,2 @@ | ||
t.fail() | ||
} | ||
main() | ||
}) |
@@ -12,17 +12,15 @@ 'use strict' | ||
t.autoend(false) | ||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
req.on('data', () => undefined) | ||
req.on('end', () => { | ||
res.flushHeaders() | ||
clock.setTimeout(() => { | ||
res.end() | ||
t.end() | ||
}, 1000) | ||
t.test('undici body timeout', async (t) => { | ||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
req.on('data', () => undefined) | ||
req.on('end', () => { | ||
res.flushHeaders() | ||
clock.setTimeout(() => { | ||
res.end() | ||
t.end() | ||
}, 1000) | ||
}) | ||
}) | ||
}) | ||
async function main () { | ||
await target.listen({ port: 0 }) | ||
@@ -62,4 +60,2 @@ | ||
t.fail() | ||
} | ||
main() | ||
}) |
@@ -11,17 +11,15 @@ 'use strict' | ||
t.autoend(false) | ||
t.test('undici request timeout', async (t) => { | ||
const target = Fastify() | ||
t.teardown(target.close.bind(target)) | ||
const target = Fastify() | ||
t.teardown(target.close.bind(target)) | ||
target.get('/', (request, reply) => { | ||
t.pass('request arrives') | ||
target.get('/', (request, reply) => { | ||
t.pass('request arrives') | ||
clock.setTimeout(() => { | ||
reply.status(200).send('hello world') | ||
t.end() | ||
}, 1000) | ||
}) | ||
clock.setTimeout(() => { | ||
reply.status(200).send('hello world') | ||
t.end() | ||
}, 1000) | ||
}) | ||
async function main () { | ||
await target.listen({ port: 0 }) | ||
@@ -61,4 +59,2 @@ | ||
t.fail() | ||
} | ||
main() | ||
}) |
@@ -1,2 +0,2 @@ | ||
import fastify, { FastifyReply, FastifyRequest, RawServerBase, RequestGenericInterface } from "fastify"; | ||
import fastify, { FastifyReply, FastifyRequest, RawReplyDefaultExpression, RawServerBase, RequestGenericInterface } from "fastify"; | ||
import * as http from 'http'; | ||
@@ -51,3 +51,2 @@ import { IncomingHttpHeaders } from "http2"; | ||
}; | ||
tap.autoend(false); | ||
@@ -82,2 +81,8 @@ async function main() { | ||
return base; | ||
}, | ||
onResponse(request, reply, res) { | ||
expectType<FastifyRequest<RequestGenericInterface, RawServerBase>>(request); | ||
expectType<FastifyReply<RawServerBase>>(reply); | ||
expectType<RawReplyDefaultExpression<RawServerBase>>(res); | ||
expectType<number>(res.statusCode); | ||
} | ||
@@ -84,0 +89,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
199523
113
5736
512
1
+ Addedundici@6.19.2(transitive)
- Removed@fastify/busboy@2.1.1(transitive)
- Removedundici@5.28.4(transitive)
Updated@fastify/error@^3.4.1
Updatedfast-querystring@^1.1.2
Updatedfastify-plugin@^4.5.1
Updatedundici@^6.11.1