Skip to content

The node:http and deno serve APIs silently drop the fragment part of http get/request/... #31480

@BerndAmend

Description

@BerndAmend

Version: Deno 2.5.6
Node Version: v25.2.1

The node:http and deno serve APIs silently drop the fragment part of http get/request/...
For the fetch API this is expected, but not for node:http and deno serve.

I noticed this issue while implementing WebDav with deno.
The test suites (litmus) require the server to reject invalid http requests (in this case containing a #) which is not possible in deno, since they are silently dropped from http requests. I think this is in general undesired behavior.

Source: https://github.com/BerndAmend/deno-serve-fragment-test

The Web server created either using node:http

import * as http from "node:http";

http.createServer(function (req, res) {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end(req.url);
}).listen(8000);

or deno serve

export default {
  async fetch(req: Request) {
    return new Response(req.url, { status: 200 });
  },
};

Client Code

import * as http from "node:http";

console.log(
  "send: " +
    http.get({ hostname: "localhost", port: 8000, path: "/f#f" }, (res) => {
      res.on("data", (chunk) => console.log("received: " + chunk.toString()));
    }).path,
);

Node returns the expected output

$ node node_server.ts 
$ node client.ts
send: /f#f
received: /f#f

Deno does not

$ deno run -N node_server.ts 
$ node client.ts
send: /f#f
received: /f
$ deno serve deno_server.ts
$ node client.ts
send: /f#f
received: http://localhost:8000/f

The client side API is also incorrect in deno

$ node node_server.ts 
$ deno run -N client.ts
send: /f#f
received: /f

Metadata

Metadata

Assignees

No one assigned

    Labels

    ext/httprelated to ext/httpneeds investigationrequires further investigation before determining if it is an issue or notnode:httpIssues with `node:http` module - to be fixed with a rewrite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions