question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP Date header time faking fails on Node 15.2.0 and later

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamingrcommented, Nov 5, 2021
2reactions
aduh95commented, Jan 5, 2021

I quite like the flag idea as it gives to users the more power over how Node.js internals behave. What about a --expose-primordials flag? I think it would be easier to implement than a --no-primordials one, and would allow users to define a specific behaviour for Node.js internals without even changing the globals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node express server not affected by sinon's useFakeTimers
See HTTP Date header time faking fails on Node 15.2.0 and later - https://github.com/sinonjs/fake-timers/issues/344.
Read more >
Issues · sinonjs/fake-timers - GitHub
Fake setTimeout and friends (collectively known as "timers"). ... HTTP Date header time faking fails on Node 15.2.0 and later awaiting maintainer feedback ......
Read more >
Date - HTTP - MDN Web Docs - Mozilla
The Date general HTTP header contains the date and time at which the message originated.
Read more >
Changelog - Cypress Documentation
Removed automatic retries for failed HTTP requests through the proxy. This fixes an issue where failed requests could be re-sent too many times...
Read more >
Bug listing with status RESOLVED with resolution TEST ...
... of install after boot gentoo screen" status:RESOLVED resolution:TEST-REQUEST ... fails to load when livecd boots for the first time" status:RESOLVED ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found