HTTP Date header time is faked just fine up to Node v15.1.0 but fails with Node v15.2.0 or later.
- FakeTimers version :
6.0.1
- Environment :
Node v15.5.0
- Other libraries you are using:
assert, http
What did you expect to happen?
Should return HTTP Date header with fake time date: "Tue, 31 Dec 2013 23:59:59 GMT".
What actually happens
Instead returns HTTP Date header with current time, e.g. date: "Sun, 03 Jan 2021 17:22:52 GMT".
How to reproduce
Following is a minimal and complete mocha test case that reproduces the issue
import assert from "assert";
import http from "http";
import fake_timers from "@sinonjs/fake-timers";
describe("fake HTTP Date header time", function()
{
let clock;
let server;
before(function(done)
{
clock = fake_timers.install({now: Date.parse("2013-12-31 23:59:59.123Z")});
server = http.createServer((req, res) =>
{
req.on("data", () => void null);
req.on("end", () =>
{
res.writeHead(200);
res.end();
});
});
server.listen(8080, done);
});
after(function(done)
{
clock.uninstall();
server.close(done);
});
it("should fake HTTP Date header time", function(done)
{
const expectedHeaders =
{
"connection": "close",
"date": "Tue, 31 Dec 2013 23:59:59 GMT",
"transfer-encoding": "chunked"
};
const opts =
{
hostname: "localhost",
method: "GET",
path: "/",
port: 8080
};
const req = http.request(opts, (res) =>
{
const {headers, statusCode, statusMessage} = res;
res.on("data", () => void null);
res.on("end", () =>
{
assert.strictEqual(statusCode, 200);
assert.strictEqual(statusMessage, "OK");
assert.deepStrictEqual(headers, expectedHeaders);
done();
});
});
req.end();
});
});
Note
Starting with Node 15.2.0 http.js imports Date from primordials while Node 15.1.0 http.js just uses the global Date object.
HTTP
Dateheader time is faked just fine up toNode v15.1.0but fails withNode v15.2.0or later.6.0.1Node v15.5.0assert,httpWhat did you expect to happen?
Should return HTTP
Dateheader with fake timedate: "Tue, 31 Dec 2013 23:59:59 GMT".What actually happens
Instead returns HTTP
Dateheader with current time, e.g.date: "Sun, 03 Jan 2021 17:22:52 GMT".How to reproduce
Following is a minimal and complete mocha test case that reproduces the issue
Note
Starting with Node 15.2.0 http.js imports
Datefromprimordialswhile Node 15.1.0 http.js just uses the globalDateobject.