diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 27 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index d12a93867..b4d248440 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1618,6 +1618,33 @@ Deno.test( }, ); +Deno.test( + { permissions: { net: true } }, + async function createHttpClientExplicitResourceManagement() { + using client = Deno.createHttpClient({}); + const response = await fetch("http://localhost:4545/assets/fixture.json", { + client, + }); + const json = await response.json(); + assertEquals(json.name, "deno"); + }, +); + +Deno.test( + { permissions: { net: true } }, + async function createHttpClientExplicitResourceManagementDoubleClose() { + using client = Deno.createHttpClient({}); + const response = await fetch("http://localhost:4545/assets/fixture.json", { + client, + }); + const json = await response.json(); + assertEquals(json.name, "deno"); + // Close the client even though we declared it with `using` to confirm that + // the cleanup done as per `Symbol.dispose` will not throw any errors. + client.close(); + }, +); + Deno.test({ permissions: { read: false } }, async function fetchFilePerm() { await assertRejects(async () => { await fetch(import.meta.resolve("../testdata/subdir/json_1.json")); diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 2890a50ff..bdb0493b0 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -847,7 +847,7 @@ declare namespace Deno { * * @category Fetch API */ - export interface HttpClient { + export interface HttpClient extends Disposable { /** The resource ID associated with the client. */ rid: number; /** Close the HTTP client. */ |