Skip to content

Commit

Permalink
Merge pull request #19 from matrix-org/t3chguy-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Oct 4, 2022
2 parents 5ab1d66 + 9f8d967 commit a2885f9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ class HttpBackend {

// very simplistic mapping from the whatwg fetch interface onto the request
// interface, so we can use the same mock backend for both.
public fetchFn = (input: string, init?: Omit<RequestOpts, 'uri'>): Promise<{ ok: boolean, json: () => unknown }> => {
public fetchFn = (input: URL | string, init?: Omit<RequestOpts, 'uri'>): Promise<{
ok: boolean;
status: number;
json: () => unknown;
}> => {
const url = new URL(input);
const qs = Object.fromEntries(url.searchParams);

const requestOpts = {
uri: input,
uri: url.href,
method: init?.method || 'GET',
headers: init?.headers,
body: init?.body,
qs,
};

return new Promise((resolve, reject) => {
Expand All @@ -86,6 +95,7 @@ class HttpBackend {
}
resolve({
ok: response.statusCode >= 200 && response.statusCode < 300,
status: response.statusCode,
json: () => JSON.parse(body),
});
};
Expand Down

0 comments on commit a2885f9

Please sign in to comment.