-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
index.test-d.ts
130 lines (117 loc) · 3.02 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import replyFrom, { FastifyReplyFromOptions } from "../";
import fastify, {FastifyReply, RawServerBase} from "fastify";
import { AddressInfo } from "net";
import { IncomingHttpHeaders } from "http2";
import { expectType } from 'tsd';
import * as http from 'http';
import * as https from 'https';
import * as http2 from 'http2';
// @ts-ignore
import tap from 'tap'
const fullOptions: FastifyReplyFromOptions = {
base: "http://example2.com",
http: {
agentOptions: {
keepAliveMsecs: 60 * 1000,
maxFreeSockets: 2048,
maxSockets: 2048
},
requestOptions: {
timeout: 1000
},
agents: {
'http:': new http.Agent({}),
'https:': new https.Agent({})
}
},
http2: {
sessionTimeout: 1000,
requestTimeout: 1000,
sessionOptions: {
rejectUnauthorized: true
},
requestOptions: {
endStream: true
}
},
cacheURLs: 100,
disableCache: false,
keepAliveMsecs: 60 * 1000,
maxFreeSockets: 2048,
maxSockets: 2048,
rejectUnauthorized: true,
undici: {
connections: 100,
pipelining: 10
}
};
tap.autoend(false);
async function main() {
const server = fastify();
server.register(replyFrom);
server.register(replyFrom, {});
server.register(replyFrom, {http2: true});
server.register(replyFrom, fullOptions);
server.get("/v1", (request, reply) => {
reply.from();
});
server.get("/v3", (request, reply) => {
reply.from("/v3", {
body: {hello: "world"},
rewriteRequestHeaders(req, headers) {
expectType<http.IncomingMessage | http2.Http2ServerRequest>(req);
return headers;
},
getUpstream(req, base) {
expectType<http.IncomingMessage | http2.Http2ServerRequest>(req);
return base;
}
});
});
// http2
const instance = fastify({http2: true});
// @ts-ignore
tap.tearDown(instance.close.bind(instance));
const target = fastify({http2: true});
// @ts-ignore
tap.tearDown(target.close.bind(target));
instance.get("/", (request, reply) => {
reply.from();
});
instance.get("/http2", (request, reply) => {
reply.from("/", {
rewriteHeaders(headers) {
return headers;
},
rewriteRequestHeaders(req, headers: IncomingHttpHeaders) {
return headers;
},
getUpstream(req, base) {
return base;
},
onError(reply: FastifyReply<RawServerBase>, error) {
return reply.send(error.error);
}
});
});
await target.listen(0);
const port = (target.server.address() as AddressInfo).port;
instance.register(replyFrom, {
base: `http://localhost:${port}`,
http2: true,
rejectUnauthorized: false
});
await instance.listen(0);
const undiciInstance = fastify();
undiciInstance.register(replyFrom, {
base: "http://example2.com",
undici: {
pipelining: 10,
connections: 10
}
});
await undiciInstance.ready();
tap.pass('done');
tap.end();
}
main();