Skip to content

Commit c301077

Browse files
add http2 fetch
1 parent d8439a2 commit c301077

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,8 @@
8888
"suiteNameTemplate": "{filepath}",
8989
"classNameTemplate": "{classname}",
9090
"titleTemplate": "{title}"
91+
},
92+
"dependencies": {
93+
"undici": "^7.16.0"
9194
}
92-
}
95+
}

src/orkes/OrkesConductorClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export const orkesConductorClient = async (
1616
CustomHttpRequest: HttpRequestConstructor = OrkesHttpRequest
1717
) => {
1818
const serverUrl = process.env.CONDUCTOR_SERVER_URL || config?.serverUrl;
19+
20+
if (!serverUrl) throw new Error("Conductor server URL is not set");
21+
1922
const keyId = process.env.CONDUCTOR_AUTH_KEY || config?.keyId;
2023
const keySecret = process.env.CONDUCTOR_AUTH_SECRET || config?.keySecret;
2124

src/orkes/request/OrkesHttpRequest.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ import {
44
CancelablePromise,
55
OpenAPIConfig,
66
} from "../../common";
7+
import { FetchFn } from "../types";
78
import { orkesRequest } from "./request";
9+
import {
10+
fetch as undiciFetch,
11+
Agent as UndiciAgent,
12+
RequestInfo as UndiciRequestInfo,
13+
RequestInit as UndiciRequestInit,
14+
} from "undici";
815

916
export class OrkesHttpRequest extends BaseHttpRequest {
17+
private fetchFn: FetchFn;
18+
1019
constructor(config: OpenAPIConfig) {
1120
super(config);
21+
const undiciHttp2Agent = new UndiciAgent({ allowH2: true });
22+
const undiciHttp2Fetch = async (
23+
input: UndiciRequestInfo,
24+
init: UndiciRequestInit = {}
25+
) => {
26+
return undiciFetch(input, {
27+
...init,
28+
dispatcher: undiciHttp2Agent,
29+
});
30+
};
31+
this.fetchFn = undiciHttp2Fetch as FetchFn;
1232
}
1333

1434
public request<T>(options: ApiRequestOptions): CancelablePromise<T> {
15-
return orkesRequest(this.config, options);
35+
return orkesRequest(this.config, options, this.fetchFn);
1636
}
1737
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,11 @@ undici-types@~6.21.0:
34453445
resolved "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz"
34463446
integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==
34473447

3448+
undici@^7.16.0:
3449+
version "7.16.0"
3450+
resolved "https://registry.yarnpkg.com/undici/-/undici-7.16.0.tgz#cb2a1e957726d458b536e3f076bf51f066901c1a"
3451+
integrity sha512-QEg3HPMll0o3t2ourKwOeUAZ159Kn9mx5pnzHRQO8+Wixmh88YdZRiIwat0iNzNNXn0yoEtXJqFpyW7eM8BV7g==
3452+
34483453
update-browserslist-db@^1.1.3:
34493454
version "1.1.3"
34503455
resolved "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.3.tgz"

0 commit comments

Comments
 (0)