Open
Description
opened on Dec 17, 2024
Version
v22.10.0
Platform
Darwin ... 24.2.0 Darwin Kernel Version 24.2.0: ...; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000 arm64 arm Darwin
Subsystem
http
What steps will reproduce the bug?
Start a simple HTTP server.
import http from "node:http";
http.createServer(function (req, res) {
res.end("hello");
}).listen(3000);
Send it an HTTP/1.0 request using cURL.
$ curl --http1.0 -XGET -I 127.0.0.1:3000
HTTP/1.1 200 OK
Date: Tue, 17 Dec 2024 03:26:02 GMT
Connection: close
How often does it reproduce? Is there a required condition?
Consistently reproducible.
What is the expected behavior? Why is that the expected behavior?
I would expect the response to include a Content-Length
header.
What do you see instead?
The response does not include a Content-Length
header.
Additional information
If we instead send an HTTP/1.1 request (either with or without Keep-Alive
), the Content-Length
header is included.
$ curl --http1.1 -XGET -I 127.0.0.1:3000
HTTP/1.1 200 OK
Date: Tue, 17 Dec 2024 03:31:41 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 5
$ curl --http1.1 -H"Connection: close" -XGET -I 127.0.0.1:3000
HTTP/1.1 200 OK
Date: Tue, 17 Dec 2024 03:32:35 GMT
Connection: close
Content-Length: 5
This seems strange. I would expect to see a Content-Length
header regardless of whether the request was HTTP/1.0 or HTTP/1.1.
Attaching a debugger, the HTTP/1.0 request triggers the former clause and the HTTP/1.1 request triggers the latter clause in the following HTTP server code.
Lines 553 to 559 in 2cd385e
Activity