/**
 * Analyzes X-Cache headers from caching servers like Squid or Varnish
 */
exports.version = '0.1';

exports.module = function(phantomas) {
	phantomas.setMetric('cacheHits');
	phantomas.setMetric('cacheMisses');
	phantomas.setMetric('cachePasses');

	var re = /miss|hit|pass/i;
	
	// examples:
	// X-Cache:HIT, HIT
	// X-Cache:arsenic miss (0)
	phantomas.on('recv', function(entry,res) {
		var header = entry.headers['X-Cache'].toLowerCase() || '',
			isHit,
			isPass;

		if (re.test(header)) {
			isHit = header.indexOf('hit') > -1;
			if (isHit) {
				phantomas.incrMetric('cacheHits');
			}
			else {
				isPass = header.indexOf('pass') > -1;
				if (isPass) {
					phantomas.incrMetric('cachePasses');
					phantomas.addOffender('cachePasses', entry.url);
					phantomas.log('Cache pass: on <' + entry.url + '> (X-Cache: ' + header + ')');
				}
				else {
					phantomas.incrMetric('cacheMisses');
					phantomas.log('Cache miss: on <' + entry.url + '> (X-Cache: ' + header + ')');
				}
			}
		}
	});
};

@@ -400,16 +400,17 @@
 eader = 
+(
 entry.he
@@ -425,16 +425,23 @@
 -Cache'%5D
+ %7C%7C '')
 .toLower
@@ -446,22 +446,16 @@
 erCase()
- %7C%7C ''
 ,%0A%09%09%09isH

add a check for undefined