mcavage/node-restify — pull request #65 by fnogatz (2012-01-31 21:54:18+00:00)
Title: ETag support (If-None-Match)

Hi Mark,

this pull request is related to the issue #25. Sorry, I don't know how it would be possible to start the pull request right into this thread :)
I've added a plugin to support ETags, especially with the If-None-Match header. I'll implement other conditions too if you agree with my approach.

You can use the restify.eTagChecker like the other plugins:

var restify = require('restify');
var server = restify.createServer();

function generator(req) {
// do sth special to get the current ETag, e.g. a database request
return 'myETag';
}
server.use(restify.eTagChecker(generator));

server.get('/test', function(req, res, next) {
res.send(200);
});
server.put('/test', function(req, res, next) {
res.send(201);
});

server.listen(8080);

If the ETag matches, it will return a 304 (GET & HEAD) or 412 (others). Otherwise it will add the ETag header in the server's response if provided by the generator function.

Greetings from Germany,
Falco