Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf/http2 #286

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/network-support/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class FetchError extends Error {
export function createFetch(
orderManager: OrderManager,
maxRetries = 5,
logger?: Logger
logger?: Logger,
overrideFetch?: typeof fetch
): (init: RequestInit) => Promise<Response> {
let retries = 0;
let triedFallback = false;
Expand Down Expand Up @@ -64,14 +65,18 @@ export function createFetch(
}
const { url, headers, type, runner, channelId } = requestParams;
try {
const _res = await customFetch(url, {
headers: {
...(init.headers || {}),
...headers,
const _res = await customFetch(
url,
{
headers: {
...(init.headers || {}),
...headers,
},
method: 'post',
body: init.body,
},
method: 'post',
body: init.body,
});
overrideFetch
);
let res: object;
if (type === OrderType.flexPlan) {
[res] = orderManager.extractChannelState(
Expand Down
6 changes: 4 additions & 2 deletions packages/network-support/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export const timeoutController = () => {

export const customFetch = (
input: URL | RequestInfo,
init?: RequestInit | undefined
init?: RequestInit | undefined,
overrideFetch?: typeof fetch
): Promise<Response> => {
return fetch(input, {
overrideFetch = overrideFetch ?? fetch;
return overrideFetch(input, {
signal: timeoutController().signal,
...init,
});
Expand Down
Loading