@fastify/reply-from 9.4.0 → 9.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/.gitattributes +2 -0
- package/README.md +78 -22
- package/index.js +32 -24
- package/lib/request.js +4 -4
- package/lib/utils.js +2 -0
- package/package.json +3 -2
- 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/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/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-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.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 +1 -1
- package/test/http-agents.test.js +2 -2
- package/test/http-global-agent.test.js +1 -1
- package/test/http-retry.test.js +1 -1
- package/test/http2-http2.test.js +2 -2
- package/test/http2-https.test.js +2 -2
- package/test/https-agents.test.js +4 -4
- package/test/https-global-agent.test.js +3 -3
- package/test/method.test.js +1 -1
- 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/onResponse.test.js +1 -1
- 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 +162 -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 +2 -2
- package/test/undici-agent.test.js +1 -1
- package/test/undici-body.test.js +1 -1
- package/test/undici-connect-timeout.test.js +2 -2
- package/test/undici-global-agent.test.js +1 -1
- package/test/undici-options.test.js +1 -1
- package/test/undici-retry.test.js +1 -1
- package/test/undici-timeout-body-partial.test.js +1 -1
- package/test/undici-timeout-body.test.js +1 -1
- 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 +24 -15
- package/types/index.test-d.ts +15 -6
package/test/unix-https.test.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const https = require('https')
|
|
6
|
+
const https = require('node:https')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
|
-
const fs = require('fs')
|
|
9
|
-
const querystring = require('querystring')
|
|
10
|
-
const path = require('path')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const querystring = require('node:querystring')
|
|
10
|
+
const path = require('node:path')
|
|
11
11
|
const certs = {
|
|
12
12
|
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
|
|
13
13
|
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
|
package/types/index.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
FastifyPluginCallback,
|
|
5
5
|
FastifyReply,
|
|
6
|
+
FastifyRequest,
|
|
7
|
+
HTTPMethods,
|
|
6
8
|
RawReplyDefaultExpression,
|
|
7
9
|
RawServerBase,
|
|
8
10
|
RequestGenericInterface,
|
|
9
|
-
HTTPMethods,
|
|
10
|
-
FastifyPluginCallback,
|
|
11
11
|
} from 'fastify';
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
+
Agent,
|
|
15
|
+
AgentOptions,
|
|
14
16
|
IncomingHttpHeaders,
|
|
15
17
|
RequestOptions,
|
|
16
|
-
AgentOptions,
|
|
17
|
-
Agent,
|
|
18
18
|
} from "http";
|
|
19
19
|
import {
|
|
20
|
-
RequestOptions as SecureRequestOptions,
|
|
21
|
-
AgentOptions as SecureAgentOptions,
|
|
22
|
-
Agent as SecureAgent
|
|
23
|
-
} from "https";
|
|
24
|
-
import {
|
|
25
|
-
IncomingHttpHeaders as Http2IncomingHttpHeaders,
|
|
26
|
-
ClientSessionRequestOptions,
|
|
27
20
|
ClientSessionOptions,
|
|
21
|
+
ClientSessionRequestOptions,
|
|
22
|
+
IncomingHttpHeaders as Http2IncomingHttpHeaders,
|
|
28
23
|
SecureClientSessionOptions,
|
|
29
24
|
} from "http2";
|
|
30
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
Agent as SecureAgent,
|
|
27
|
+
AgentOptions as SecureAgentOptions,
|
|
28
|
+
RequestOptions as SecureRequestOptions
|
|
29
|
+
} from "https";
|
|
30
|
+
import { Pool } from 'undici';
|
|
31
31
|
|
|
32
32
|
declare module "fastify" {
|
|
33
33
|
interface FastifyReply {
|
|
@@ -39,12 +39,21 @@ declare module "fastify" {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
type FastifyReplyFrom = FastifyPluginCallback<fastifyReplyFrom.FastifyReplyFromOptions>
|
|
42
|
-
|
|
43
42
|
declare namespace fastifyReplyFrom {
|
|
44
43
|
type QueryStringFunction = (search: string | undefined, reqUrl: string) => string;
|
|
44
|
+
|
|
45
|
+
export type RetryDetails = {
|
|
46
|
+
err: Error;
|
|
47
|
+
req: FastifyRequest<RequestGenericInterface, RawServerBase>;
|
|
48
|
+
res: FastifyReply<RawServerBase>;
|
|
49
|
+
attempt: number;
|
|
50
|
+
getDefaultDelay: () => number | null;
|
|
51
|
+
}
|
|
45
52
|
export interface FastifyReplyFromHooks {
|
|
46
53
|
queryString?: { [key: string]: unknown } | QueryStringFunction;
|
|
47
54
|
contentType?: string;
|
|
55
|
+
retryDelay?: (details: RetryDetails) => {} | null;
|
|
56
|
+
retriesCount?: number;
|
|
48
57
|
onResponse?: (
|
|
49
58
|
request: FastifyRequest<RequestGenericInterface, RawServerBase>,
|
|
50
59
|
reply: FastifyReply<RawServerBase>,
|
|
@@ -99,7 +108,7 @@ declare namespace fastifyReplyFrom {
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
export const fastifyReplyFrom: FastifyReplyFrom
|
|
102
|
-
export { fastifyReplyFrom as default }
|
|
111
|
+
export { fastifyReplyFrom as default };
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
declare function fastifyReplyFrom(...params: Parameters<FastifyReplyFrom>): ReturnType<FastifyReplyFrom>
|
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, RawServerBase, RequestGenericInterface } 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",
|
|
@@ -91,6 +91,15 @@ async function main() {
|
|
|
91
91
|
instance.get("/http2", (request, reply) => {
|
|
92
92
|
reply.from("/", {
|
|
93
93
|
method: "POST",
|
|
94
|
+
retryDelay: ({err, req, res, attempt, getDefaultDelay}) => {
|
|
95
|
+
const defaultDelay = getDefaultDelay();
|
|
96
|
+
if (defaultDelay) return defaultDelay;
|
|
97
|
+
|
|
98
|
+
if (res && res.statusCode === 500 && req.method === "GET") {
|
|
99
|
+
return 300;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
},
|
|
94
103
|
rewriteHeaders(headers, req) {
|
|
95
104
|
return headers;
|
|
96
105
|
},
|