diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-09-05 14:13:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 14:13:06 +0900 |
commit | e799c2857c81f7656811aaf6a248432fe88e8169 (patch) | |
tree | 98d91c90b9020251b71e4d12dc2bf8618e02599c /tests/unit | |
parent | 186f7484da3116aeda474f7f529d417ee542b450 (diff) |
fix(ext/http): do not set localhost to hostname unnecessarily (#24777)
This commit changes when to cause the hostname substition of `0.0.0.0` ->
`localhost`.
Currently we substitute `localhost` to the hostname on windows before
calling `options.onListen`, which prevents the users to do more advanced
thing using hostname string like
https://github.com/denoland/std/issues/5558. This PR changes it not to
substitute it when the user provide `onListen` callback.
closes #24776
unblocks https://github.com/denoland/std/issues/5558
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/serve_test.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index fde6c7bee..19a8ccad1 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -4191,3 +4191,19 @@ Deno.test({ 'Operation `"op_net_listen_unix"` not supported on non-unix platforms.', ); }); + +Deno.test({ + name: "onListen callback gets 0.0.0.0 hostname as is", +}, async () => { + const { promise, resolve } = Promise.withResolvers<{ hostname: string }>(); + + const server = Deno.serve({ + handler: (_) => new Response("ok"), + hostname: "0.0.0.0", + port: 0, + onListen: resolve, + }); + const { hostname } = await promise; + assertEquals(hostname, "0.0.0.0"); + await server.shutdown(); +}); |