4 * Copyright(c) 2010 Sencha Inc.
5 * Copyright(c) 2011 TJ Holowaychuk
10 * Module dependencies.
13 var fs = require('fs')
14 , utils = require('../utils');
23 * By default serves the connect favicon, or the favicon
24 * located by the given `path`.
28 * - `maxAge` cache-control max-age directive, defaulting to 1 day
32 * connect.createServer(
36 * connect.createServer(
37 * connect.favicon(__dirname + '/public/favicon.ico')
40 * @param {String} path
41 * @param {Object} options
46 module.exports = function favicon(path, options){
47 var options = options || {}
48 , path = path || __dirname + '/../public/favicon.ico'
49 , maxAge = options.maxAge || 86400000;
51 return function favicon(req, res, next){
52 if ('/favicon.ico' == req.url) {
54 res.writeHead(200, icon.headers);
57 fs.readFile(path, function(err, buf){
58 if (err) return next(err);
61 'Content-Type': 'image/x-icon'
62 , 'Content-Length': buf.length
63 , 'ETag': '"' + utils.md5(buf) + '"'
64 , 'Cache-Control': 'public, max-age=' + (maxAge / 1000)
68 res.writeHead(200, icon.headers);