node.js - On Heroku, why can't I see all the request headers with nodejs? -


i'm trying control static files cache headers in nodejs app described here https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers#conditional-requests. use "etag"/"if-none-match" method.

the problem request's "if-none-match" header undefined on heroku. works fine on dev server.

here fs.readfile call :

fs.readfile(serverdir+'client/'+file, function(err, data) {     if(err) {         console.log(currtime() + ' [static] ... ' + err);         if(err.code === "enoent") {      // file missing             resnotfound(res,'file not found',err);         } else {                        // other error; eacces or             resinternalerror(res,'internal server error',err);         }     }     else {         fs.stat(serverdir+'client/'+file, function (err, stat) {             if (err) {                 resinternalerror(res,'internal server error',err);             }             else {                 var etag = stat.size + '-' + date.parse(stat.mtime);                 res.setheader('last-modified', stat.mtime);                 if(logstatic) { console.log(currtime() + ' [static] ... etag : ' + etag); }                 if(logstatic) { console.log(currtime() + ' [static] ... req.if-none-match : ' + req.headers['if-none-match']); }                 if(logstatic) { console.log(req.headers); }                  if (req.headers['if-none-match'] === etag) {                     res.statuscode = 304;                     res.end();                 }                 else {                     res.setheader('content-length', data.length);                     res.setheader('etag', etag);                     res.statuscode = 200;                     res.end(data);                 }             }         });     } }); 

here heroku logs single file request :

2013-05-03t10:32:05.461070+00:00 heroku[router]: at=info method=get path=/css/common.css host=www.chess-hub.net fwd="193.252.157.50" dyno=web.1 connect=0ms service=5ms status=200 bytes=792 2013-05-03t10:32:05.455619+00:00 app[web.1]: 10:32 [static] ... serving client//css/common.css 2013-05-03t10:32:05.457981+00:00 app[web.1]: { 'x-request-start': '1367577125454', 2013-05-03t10:32:05.457981+00:00 app[web.1]:   'x-forwarded-port': '80', 2013-05-03t10:32:05.455443+00:00 app[web.1]: 10:32 [static] client file request 2013-05-03t10:32:05.457981+00:00 app[web.1]:   'x-forwarded-proto': 'http', 2013-05-03t10:32:05.456127+00:00 app[web.1]: 10:32 [static] ... req if-none-match : undefined 2013-05-03t10:32:05.457981+00:00 app[web.1]:   cookie: 'bcsi-cs-56c420186ecc3f22=2', 2013-05-03t10:32:05.457981+00:00 app[web.1]:   dnt: '1', 2013-05-03t10:32:05.457981+00:00 app[web.1]:   'cache-control': 'max-age=0', 2013-05-03t10:32:05.457981+00:00 app[web.1]:   'x-forwarded-for': '193.252.157.50', 2013-05-03t10:32:05.456046+00:00 app[web.1]: 10:32 [static] ... etag : 792-1367572582000 2013-05-03t10:32:05.457981+00:00 app[web.1]:   host: 'www.chess-hub.net', 2013-05-03t10:32:05.458231+00:00 app[web.1]:   accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } 2013-05-03t10:32:05.457981+00:00 app[web.1]:   'user-agent': 'mozilla/5.0 (windows nt 5.1; rv:19.0) gecko/20100101 firefox/19.0', 2013-05-03t10:32:05.458231+00:00 app[web.1]:   'accept-language': 'fr-fr,en-us;q=0.5', 2013-05-03t10:32:05.457981+00:00 app[web.1]:   connection: 'close', 2013-05-03t10:32:05.458231+00:00 app[web.1]:   'accept-encoding': 'gzip, deflate', 

... , it. not sure how heroku truncates output when saving logs.

thanks help.

edit : looks issue somehow linked fact connecting via proxy. when skip it, heroku logs correctly display "if-none-match" header , app returns http/304 code. proxy adds huge "proxy-authorization" token request, length limitation in headers ?

there 2 problems may causing behavior observing:

  • etag , last-modifed redundant headers, should using 1 of two. because returning both, browser may sending if-modified-since instead of if-none-match. seems in case last-modified header more suitable etags.
  • you not explicitly configuring responses cacheable, browser may decide not cache @ all. try returning cache-control:public, max-age=2592000, must-revalidate or expires (but not both)

see this guide explanation of cache control headers.

a tool firebug check headers browser sends , receives.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -