From c7535950b6de086fce741809728129c79288dee8 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 15 Feb 2023 16:37:41 +0100 Subject: feat(flash): add 2nd param to handler to get remote address (#17633) Closes #17583 --- cli/tests/unit/flash_test.ts | 4 +++- cli/tsc/dts/lib.deno.unstable.d.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts index 9ed0276a6..0924aab66 100644 --- a/cli/tests/unit/flash_test.ts +++ b/cli/tests/unit/flash_test.ts @@ -89,12 +89,14 @@ Deno.test({ permissions: { net: true } }, async function httpServerBasic() { const listeningPromise = deferred(); const server = Deno.serve({ - handler: async (request) => { + handler: async (request, getRemoteAddr) => { // FIXME(bartlomieju): // make sure that request can be inspected console.log(request); assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/"); assertEquals(await request.text(), ""); + const addr = getRemoteAddr(); + assertEquals(addr.hostname, "127.0.0.1"); promise.resolve(); return new Response("Hello World", { headers: { "foo": "bar" } }); }, diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 822425d05..0362b416d 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1126,7 +1126,7 @@ declare namespace Deno { * * @category HTTP Server */ - export type ServeHandler = (request: Request) => Response | Promise; + export type ServeHandler = (request: Request, getRemoteAddr: () => Deno.NetAddr) => Response | Promise; /** **UNSTABLE**: New API, yet to be vetted. * -- cgit v1.2.3