Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ import { methods as METHODS } from "node:_http_common";
import { deprecate } from "node:util";

const { internalRidSymbol } = core;
const { ArrayIsArray, StringPrototypeToLowerCase, SafeArrayIterator } =
primordials;
const {
ArrayIsArray,
StringPrototypeIncludes,
StringPrototypeToLowerCase,
SafeArrayIterator,
} = primordials;

type Chunk = string | Buffer | Uint8Array;

Expand Down Expand Up @@ -969,9 +973,9 @@ class ClientRequest extends OutgoingMessage {
path = "/" + path;
}
const url = new URL(
`${protocol}//${auth ? `${auth}@` : ""}${host}${
port === 80 ? "" : `:${port}`
}${path}`,
`${protocol}//${auth ? `${auth}@` : ""}${
StringPrototypeIncludes(host, ":") ? `[${host}]` : host
}${port === 80 ? "" : `:${port}`}${path}`,
);
url.hash = hash;
return url.href;
Expand Down
17 changes: 15 additions & 2 deletions tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// deno-lint-ignore-file no-console

import EventEmitter from "node:events";
import { EventEmitter, once } from "node:events";
import http, {
IncomingMessage,
type RequestOptions,
Expand All @@ -11,7 +11,7 @@ import http, {
import url from "node:url";
import https from "node:https";
import zlib from "node:zlib";
import net, { Socket } from "node:net";
import net, { type AddressInfo, Socket } from "node:net";
import fs from "node:fs";
import { text } from "node:stream/consumers";

Expand Down Expand Up @@ -441,6 +441,19 @@ Deno.test("[node/http] request with headers", async () => {
await promise;
});

Deno.test("[node/http] request with ipv6 host", async () => {
const server = http.createServer((_req, res) => res.end()).listen(0, "::1");
await once(server, "listening");
const { port } = server.address() as AddressInfo;
const req = http.request(`http://[::1]:${port}`).end();
const [res] = await once(req, "response") as [IncomingMessage];
assertEquals(res.statusCode, 200);
res.resume();
await once(res, "end");
server.close();
await once(server, "close");
});

Deno.test("[node/http] non-string buffer response", {
// TODO(kt3k): Enable sanitizer. A "zlib" resource is leaked in this test case.
sanitizeResources: false,
Expand Down
Loading