Headers not setting with redirect using node.js / Express

Viewed 15964

I am relatively new to node.js, Express, and mobile development, and have run into a problem that I think has to do with sending headers with Express.

The user starts at the home page '/', not logged in, then clicks a button to go to the sign-in page. When they submit their username and password to '/validate_signin', they should be redirected back to the home page, this time with the home page showing up differently because they are logged in.

The redirection worked like this:

res.redirect('/');

This works fine on my laptop, but on my mobile phone it redirects to '/', in its old state, presumably because of caching. If I refresh the page on the phone, '/' will show up as it should.

I found this post: How to control web page caching, across all browsers?

Have tried to set headers in the following two ways (separately), but they don't seem to be sending:

res.header("Cache-Control", "no-cache, no-store, must-revalidate");
res.header("Pragma", "no-cache");
res.header("Expires", 0);

res.writeHead(302, {
    "location": "/",
    "Cache-Control" : "no-cache, no-store, must-revalidate",
    "Pragma": "no-cache",
    "Expires": 0
});

Here are the headers that I am currently receiving:

HTTP/1.1 304 Not Modified
X-Powered-By: Express
Date: Fri, 13 Jul 2012 17:35:18 GMT
Cache-Control: public, max-age=0
Last-Modified: Fri, 13 Jul 2012 12:32:12 GMT
Etag: "3223-1342182732000"
Accept-Ranges: bytes
Connection: keep-alive

Any ideas?

Many thanks.

1 Answers
Related