@fastify/reply-from 10.0.0 → 11.0.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/.gitattributes +2 -0
- package/.github/workflows/ci.yml +1 -1
- package/.taprc +1 -9
- package/README.md +114 -29
- package/index.js +55 -47
- package/lib/request.js +32 -12
- package/lib/utils.js +8 -0
- package/package.json +25 -22
- package/test/async-route-handler.test.js +1 -1
- package/test/base-get.test.js +1 -1
- package/test/base-querystring.test.js +1 -1
- package/test/build-url.test.js +9 -2
- package/test/core-with-path-in-base.test.js +1 -1
- package/test/custom-undici-instance.test.js +1 -1
- package/test/disable-request-logging.test.js +1 -1
- package/test/fastify-multipart-incompatibility.test.js +3 -3
- package/test/fix-GHSA-v2v2-hph8-q5xp.test.js +47 -0
- package/test/full-delete-http2.test.js +52 -0
- package/test/full-get-test.test.js +1 -1
- package/test/full-https-get.test.js +3 -3
- package/test/full-post-extended-content-type.test.js +1 -1
- package/test/full-post-http2.test.js +2 -0
- package/test/full-post-stream-core.test.js +1 -1
- package/test/full-post-stream.test.js +1 -1
- package/test/full-post.test.js +1 -1
- package/test/full-querystring-rewrite-option-complex.test.js +1 -1
- package/test/full-querystring-rewrite-option-function-request.test.js +58 -0
- package/test/full-querystring-rewrite-option-function.test.js +2 -2
- package/test/full-querystring-rewrite-option.test.js +1 -1
- package/test/full-querystring-rewrite-string.test.js +1 -1
- package/test/full-querystring-rewrite.test.js +1 -1
- package/test/full-querystring.test.js +1 -1
- package/test/full-rewrite-body-content-type.test.js +1 -1
- package/test/full-rewrite-body-http.test.js +1 -1
- package/test/full-rewrite-body-to-empty-string.test.js +1 -1
- package/test/full-rewrite-body-to-null.test.js +1 -1
- package/test/full-rewrite-body.test.js +1 -1
- package/test/get-upstream-http.test.js +1 -1
- package/test/get-upstream-type.test.js +1 -1
- package/test/get-upstream-undici.test.js +1 -1
- package/test/get-with-body.test.js +1 -1
- package/test/head-with-body.test.js +7 -1
- package/test/http-agents.test.js +2 -2
- package/test/http-global-agent.test.js +1 -1
- package/test/http-http2.test.js +2 -0
- package/test/http-retry.test.js +1 -1
- package/test/http-timeout.test.js +0 -2
- package/test/http2-http2.test.js +4 -2
- package/test/http2-https.test.js +2 -2
- package/test/http2-invalid-base.test.js +1 -1
- package/test/http2-timeout-disabled.test.js +85 -0
- package/test/http2-timeout.test.js +2 -0
- package/test/http2-unix-socket.test.js +1 -1
- package/test/https-agents.test.js +4 -4
- package/test/https-global-agent.test.js +3 -3
- package/test/method.test.js +70 -0
- package/test/modifyCoreObjects-false.test.js +1 -1
- package/test/no-body-opts-with-get.test.js +1 -1
- package/test/no-body-opts-with-head.test.js +1 -1
- package/test/no-stream-body-option.test.js +2 -2
- package/test/on-error.test.js +11 -15
- package/test/onResponse.test.js +4 -3
- package/test/padded-body.test.js +1 -1
- package/test/post-formbody.test.js +1 -1
- package/test/post-plain-text.test.js +1 -1
- package/test/post-with-custom-encoded-contenttype.test.js +2 -2
- package/test/post-with-octet-stream.test.js +2 -2
- package/test/retry-on-503.test.js +1 -1
- package/test/retry-with-a-custom-handler.test.js +186 -0
- package/test/rewrite-headers-type.test.js +1 -1
- package/test/rewrite-headers.test.js +1 -1
- package/test/rewrite-request-headers-type.test.js +1 -1
- package/test/rewrite-request-headers.test.js +1 -1
- package/test/transform-body.test.js +3 -3
- package/test/undici-agent.test.js +2 -2
- package/test/undici-body.test.js +1 -1
- package/test/undici-connect-timeout.test.js +10 -14
- package/test/undici-custom-dispatcher.test.js +73 -0
- package/test/undici-global-agent.test.js +1 -1
- package/test/undici-no-destroy.test.js +29 -0
- package/test/undici-options.test.js +1 -1
- package/test/undici-proxy-agent.test.js +81 -0
- package/test/undici-retry.test.js +1 -1
- package/test/undici-timeout-body-partial.test.js +15 -19
- package/test/undici-timeout-body.test.js +13 -17
- package/test/undici-timeout.test.js +11 -15
- package/test/undici-with-path-in-base.test.js +1 -1
- package/test/undici.test.js +1 -1
- package/test/unix-http-undici-from.test.js +3 -3
- package/test/unix-http-undici.test.js +3 -3
- package/test/unix-http.test.js +3 -3
- package/test/unix-https-undici.test.js +4 -4
- package/test/unix-https.test.js +4 -4
- package/types/index.d.ts +37 -19
- package/types/index.test-d.ts +37 -10
package/types/index.test-d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import fastify, {FastifyReply, FastifyRequest, RawServerBase, RequestGenericInterface} from "fastify";
|
|
3
|
-
import { AddressInfo } from "net";
|
|
4
|
-
import { IncomingHttpHeaders } from "http2";
|
|
5
|
-
import { expectType } from 'tsd';
|
|
1
|
+
import fastify, { FastifyReply, FastifyRequest, RawReplyDefaultExpression, RawServerBase, RequestGenericInterface, RouteGenericInterface } from "fastify";
|
|
6
2
|
import * as http from 'http';
|
|
3
|
+
import { IncomingHttpHeaders } from "http2";
|
|
7
4
|
import * as https from 'https';
|
|
5
|
+
import { AddressInfo } from "net";
|
|
6
|
+
import { expectType } from 'tsd';
|
|
7
|
+
import replyFrom, { FastifyReplyFromOptions } from "..";
|
|
8
8
|
// @ts-ignore
|
|
9
|
-
import tap from 'tap'
|
|
9
|
+
import tap from 'tap';
|
|
10
10
|
|
|
11
11
|
const fullOptions: FastifyReplyFromOptions = {
|
|
12
12
|
base: "http://example2.com",
|
|
@@ -38,15 +38,16 @@ const fullOptions: FastifyReplyFromOptions = {
|
|
|
38
38
|
disableCache: false,
|
|
39
39
|
undici: {
|
|
40
40
|
connections: 100,
|
|
41
|
-
pipelining: 10
|
|
41
|
+
pipelining: 10,
|
|
42
|
+
proxy: 'http://example2.com:8080'
|
|
42
43
|
},
|
|
43
44
|
contentTypesToEncode: ['application/x-www-form-urlencoded'],
|
|
44
45
|
retryMethods: ['GET', 'HEAD', 'OPTIONS', 'TRACE'],
|
|
45
46
|
maxRetriesOn503: 10,
|
|
46
47
|
disableRequestLogging: false,
|
|
47
48
|
globalAgent: false,
|
|
49
|
+
destroyAgent: true
|
|
48
50
|
};
|
|
49
|
-
tap.autoend(false);
|
|
50
51
|
|
|
51
52
|
async function main() {
|
|
52
53
|
const server = fastify();
|
|
@@ -59,6 +60,10 @@ async function main() {
|
|
|
59
60
|
|
|
60
61
|
server.register(replyFrom, fullOptions);
|
|
61
62
|
|
|
63
|
+
server.register(replyFrom, { undici: { proxy: new URL('http://example2.com:8080') } });
|
|
64
|
+
|
|
65
|
+
server.register(replyFrom, { undici: { proxy: { uri: 'http://example2.com:8080' } } });
|
|
66
|
+
|
|
62
67
|
server.get("/v1", (request, reply) => {
|
|
63
68
|
expectType<FastifyReply>(reply.from());
|
|
64
69
|
});
|
|
@@ -72,6 +77,12 @@ async function main() {
|
|
|
72
77
|
getUpstream(req, base) {
|
|
73
78
|
expectType<FastifyRequest<RequestGenericInterface, RawServerBase>>(req);
|
|
74
79
|
return base;
|
|
80
|
+
},
|
|
81
|
+
onResponse(request, reply, res) {
|
|
82
|
+
expectType<FastifyRequest<RequestGenericInterface, RawServerBase>>(request);
|
|
83
|
+
expectType<FastifyReply<RouteGenericInterface, RawServerBase>>(reply);
|
|
84
|
+
expectType<RawReplyDefaultExpression<RawServerBase>>(res);
|
|
85
|
+
expectType<number>(res.statusCode);
|
|
75
86
|
}
|
|
76
87
|
});
|
|
77
88
|
});
|
|
@@ -89,6 +100,16 @@ async function main() {
|
|
|
89
100
|
|
|
90
101
|
instance.get("/http2", (request, reply) => {
|
|
91
102
|
reply.from("/", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
retryDelay: ({err, req, res, attempt, retriesCount, getDefaultDelay }) => {
|
|
105
|
+
const defaultDelay = getDefaultDelay();
|
|
106
|
+
if (defaultDelay) return defaultDelay;
|
|
107
|
+
|
|
108
|
+
if (res && res.statusCode === 500 && req.method === "GET") {
|
|
109
|
+
return 300;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
},
|
|
92
113
|
rewriteHeaders(headers, req) {
|
|
93
114
|
return headers;
|
|
94
115
|
},
|
|
@@ -98,9 +119,15 @@ async function main() {
|
|
|
98
119
|
getUpstream(req, base) {
|
|
99
120
|
return base;
|
|
100
121
|
},
|
|
101
|
-
onError(reply: FastifyReply<RawServerBase>, error) {
|
|
122
|
+
onError(reply: FastifyReply<RouteGenericInterface, RawServerBase>, error) {
|
|
102
123
|
return reply.send(error.error);
|
|
103
|
-
}
|
|
124
|
+
},
|
|
125
|
+
queryString(search, reqUrl, request) {
|
|
126
|
+
expectType<string | undefined>(search);
|
|
127
|
+
expectType<string>(reqUrl);
|
|
128
|
+
expectType<FastifyRequest<RequestGenericInterface, RawServerBase>>(request);
|
|
129
|
+
return '';
|
|
130
|
+
},
|
|
104
131
|
});
|
|
105
132
|
});
|
|
106
133
|
|