Hey 👋
- Version: 13.X.X
- Platform: Windows & macOS
Since the version 13 of Node.js, the response is aborted if the Content-Length isn't matched in the body when sending back a 304.
According to the HTTP spec, we have the right to provide a Content-Length header.
A server MAY send a Content-Length header field in a 304 (Not Modified) response to a conditional GET request
Reproduction:
"use strict";consthttp=require("http");constserver=http.createServer((req,res)=>{console.log("got request");res.setHeader("Content-Length",11);res.statusCode=304;res.end(null);});server.listen(3000,()=>{console.log("listening");constrequest=http.request({hostname: "localhost",port: 3000,method: "GET",path: "/"});request.on("response",response=>{console.log("response");response.on("aborted",()=>{console.log("aborted");});response.on("close",()=>{console.log("close");});response.on("end",()=>{console.log("end");});response.on("data",console.log);});request.end("");});Logs in Node 12:
listening
got request
response
aborted
end
close
Logs in Node 13:
listening
got request
response
aborted
close
c/c @targos
Hey 👋
Since the version 13 of Node.js, the response is aborted if the
Content-Lengthisn't matched in the body when sending back a 304.According to the HTTP spec, we have the right to provide a
Content-Lengthheader.Reproduction:
Logs in Node 12:
Logs in Node 13:
c/c @targos