From 4f1b1903cfadeeba24e1b0448879fe12682effb9 Mon Sep 17 00:00:00 2001 From: Tomofumi Chiba Date: Tue, 22 Jun 2021 12:21:57 +0900 Subject: feat(fetch): add programmatic proxy (#10907) This commit adds new options to unstable "Deno.createHttpClient" API. "proxy" and "basicAuth" options were added that allow to use custom proxy when client instance is passed to "fetch" API. --- cli/tests/045_proxy_test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cli/tests/045_proxy_test.ts') diff --git a/cli/tests/045_proxy_test.ts b/cli/tests/045_proxy_test.ts index c7ba5e967..6e338f4fc 100644 --- a/cli/tests/045_proxy_test.ts +++ b/cli/tests/045_proxy_test.ts @@ -15,6 +15,11 @@ async function proxyServer(): Promise { async function proxyRequest(req: ServerRequest): Promise { console.log(`Proxy request to: ${req.url}`); + const proxyAuthorization = req.headers.get("proxy-authorization"); + if (proxyAuthorization) { + console.log(`proxy-authorization: ${proxyAuthorization}`); + req.headers.delete("proxy-authorization"); + } const resp = await fetch(req.url, { method: req.method, headers: req.headers, @@ -110,9 +115,28 @@ async function testModuleDownloadNoProxy(): Promise { http.close(); } +async function testFetchProgrammaticProxy(): Promise { + const c = Deno.run({ + cmd: [ + Deno.execPath(), + "run", + "--quiet", + "--reload", + "--allow-net=localhost:4545,localhost:4555", + "--unstable", + "045_programmatic_proxy_client.ts", + ], + stdout: "piped", + }); + const status = await c.status(); + assertEquals(status.code, 0); + c.close(); +} + proxyServer(); await testFetch(); await testModuleDownload(); await testFetchNoProxy(); await testModuleDownloadNoProxy(); +await testFetchProgrammaticProxy(); Deno.exit(0); -- cgit v1.2.3