forked from nsimmons/koa-better-http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
91 lines (85 loc) · 2.6 KB
/
types.d.ts
File metadata and controls
91 lines (85 loc) · 2.6 KB
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
import * as koa from "koa";
import * as http from "http";
declare function koaHttpProxy(
host: string,
options?: koaHttpProxy.IOptions,
): (ctx: koa.Context, next?: koa.Next) => Promise<void>;
declare namespace koaHttpProxy {
export interface IRetryOptions {
retries?: number; // maximum amount of times to retry the operation, default to 3
maxRetryTime?: number; // The maximum time (in milliseconds) that the retried operation is allowed to run, default to Infinity
minTimeout?: number; // The number of milliseconds before starting the first retry, default to 1000
maxTimeout?: number; // The maximum number of milliseconds between two retries, default to Infinity
}
export interface IProxyContainer {
proxy: {
res?: http.IncomingMessage; // The response from the proxied server
resData?: Buffer; // The response data
req?: any;
bodyContent?: any;
reqBuilder?: any;
};
user: {
ctx: koa.Context;
};
options: any;
params: any;
}
export interface IOptions {
agent?: http.Agent;
headers?: { [key: string]: any };
strippedHeaders?: [string];
https?: boolean;
limit?: string;
parseReqBody?: boolean;
port?: number;
preserveHostHdr?: boolean;
preserveReqSession?: boolean;
reqAsBuffer?: boolean;
reqBodyEncoding?: string | null;
connectTimeout?: number;
timeout?: number;
debug?:
| boolean
| {
enabled: boolean;
includeBody?: boolean;
};
filter?(ctx: koa.Context): boolean;
proxyReqBodyDecorator?(
bodyContent: string,
ctx: koa.Context,
): string | Promise<string>;
proxyReqOptDecorator?(
proxyReqOpts: IRequestOption,
ctx: koa.Context,
): IRequestOption | Promise<IRequestOption>;
proxyReqPathResolver?(ctx: koa.Context): string | Promise<string>;
userResDecorator?(
proxyRes: http.IncomingMessage,
proxyResData: string | Buffer,
ctx: koa.Context,
): string | Buffer | Promise<string> | Promise<Buffer>;
userResHeadersDecorator?(headers: {
[key: string]: string;
}): Promise<{ [key: string]: string }> | { [key: string]: string };
// Retry configuration - simplified API
retry?:
| boolean
| IRetryOptions
| ((
handle: () => Promise<IProxyContainer>,
ctx: koa.Context,
) => Promise<IProxyContainer>);
}
export interface IRequestOption {
hostname: string;
port: number;
headers: { [key: string]: any };
method: string;
path: string;
bodyContent: string | Buffer;
params: any;
}
}
export = koaHttpProxy;