Description
Version
v23.5.0
Platform
Darwin MacbookPro-2.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64 arm Darwin
Subsystem
http
What steps will reproduce the bug?
Just start the server and curl
the results:
import { createServer } from 'node:http';
const hostname = '127.0.0.1';
const port = 3000;
const server = createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
curl -v http://127.0.0.1:3000/
to get the response header through GET
;
curl -I http://127.0.0.1:3000/
to get the response header through HEAD
.
How often does it reproduce? Is there a required condition?
Always. No required condition.
What is the expected behavior? Why is that the expected behavior?
According to MDN:
The HEAD HTTP method requests the metadata of a resource in the form of headers that the server would have sent if the GET method was used instead. This method can be used in cases where a URL might produce a large download, for example, a HEAD request can read the Content-Length header to check the file size before downloading the file with a GET.
HEAD
requests are a bit different than other request methods without body because it is essentially GET
s with body removed. It should be allowed to return all the headers that a GET
request returns.
What do you see instead?
However, in the current http library, all responses without body will not return the Content-Length
header:
Line 550 in 7bc2946
Curl results:
-
-I
(HEAD
Requests)~> curl -I http://127.0.0.1:3000/ HTTP/1.1 200 OK Content-Type: text/plain Date: [redacted]
-
-v
(GET
Requests)~> curl -v http://127.0.0.1:3000/ * Trying 127.0.0.1:3000... * Connected to 127.0.0.1 (127.0.0.1) port 3000 > GET / HTTP/1.1 > Host: 127.0.0.1:3000 > User-Agent: curl/8.7.1 > Accept: */* > * Request completely sent off < HTTP/1.1 200 OK < Content-Type: text/plain < Date: [redacted] < Content-Length: 11 < * Connection #0 to host 127.0.0.1 left intact Hello World
Additional information
No response
Activity