In my nodeJS application, I would like to generate ETags for all the content that I return to the client. I need the ETag to be based on the actual contents of the file instead of the date, so that the same file in different node processes has the same ETag.
Now I am doing the following:
var fs = require('fs'), crypto = require('crypto'); fs.readFile(pathToFile, function(err, buf){ var eTag = crypto.createHash('md5').update(buf).digest('hex'); res.writeHead(200, {'ETag': '"' + eTag + '"','Content-Type':contentType}); res.end(buf); });
I'm not sure which encodings I should use for different cryptographic functions in order to have a proper system. Should I use something other than hex ? Should I get a fs.readFile call to return a hex encoded buffer? If so, will this affect the content returned to users?
Best and thanks,
Themselves
source share