-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (41 loc) · 1.4 KB
/
index.ts
File metadata and controls
47 lines (41 loc) · 1.4 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
import { ClientUtilsBase } from "./client-utils";
import { HttpClientNode as HttpClient, SendStreamOptions } from "./types";
import { normalizeUrl } from "@scramjet/utility";
import * as nodefetch from "node-fetch";
import http from "http";
import https from "https";
const nodeFetchWithHttps = (ca?: string | Buffer) =>
(req: nodefetch.RequestInfo, init?: nodefetch.RequestInit): Promise<nodefetch.Response> => {
if (typeof req === "string") {
return nodefetch.default(req, {
...init,
agent: (url) => url.protocol === "http:"
? new http.Agent({ keepAlive: true })
: new https.Agent({ keepAlive: true, ca })
});
}
throw new Error("not implemented");
};
/**
* Provides HTTP communication methods.
*
* @class ClientUtils
* @extends ClientUtilsBase
* @classdesc Provides HTTP communication methods.
*/
export class ClientUtils extends ClientUtilsBase implements HttpClient {
constructor(
apiBase: string,
ca?: string | Buffer
) {
super(apiBase, nodeFetchWithHttps(ca), normalizeUrl);
}
}
export { ClientError } from "./client-error";
export type { ClientErrorCode } from "./client-error";
export type { RequestLogger } from "./types";
export interface ClientProvider {
client: HttpClient;
}
export type { HttpClient };
export type { SendStreamOptions };