summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/http.ts3
-rw-r--r--tests/unit_node/http_test.ts18
2 files changed, 20 insertions, 1 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 015a91816..920f3a5b0 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -1781,7 +1781,8 @@ export class ServerImpl extends EventEmitter {
});
const req = new IncomingMessageForServer(socket);
- req.url = request.url?.slice(req.url.indexOf("/", 8));
+ // Slice off the origin so that we only have pathname + search
+ req.url = request.url?.slice(request.url.indexOf("/", 8));
req.method = request.method;
req.upgrade =
request.headers.get("connection")?.toLowerCase().includes("upgrade") &&
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index c0514eebd..ec20ec7d7 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -1539,3 +1539,21 @@ Deno.test("[node/http] ClientRequest PUT subarray", async () => {
await promise;
assertEquals(body, "world");
});
+
+Deno.test("[node/http] req.url equals pathname + search", async () => {
+ const { promise, resolve } = Promise.withResolvers<void>();
+
+ const server = http.createServer((req, res) => res.end(req.url));
+ server.listen(async () => {
+ const { port } = server.address() as net.AddressInfo;
+ const res = await fetch(`http://localhost:${port}/foo/bar?baz=1`);
+ const text = await res.text();
+ assertEquals(text, "/foo/bar?baz=1");
+
+ server.close(() => {
+ resolve();
+ });
+ });
+
+ await promise;
+});