<commit_before>var cache_manager = require('cache-manager'),
    fs = require('node-fs'),
    zlib = require('zlib');

module.exports = function(config){
    var defaults = {
        /**
         * Builds the path where the file are going to be stored
         * uses the default function if no other is provided (config.pathBuilder)
         * @param key String the url of the resource being processed
         * @return path String folder path like '../', 'f1/f2/f3/.../'
         */
        pathBuilder: config.pathBuilder || function(key){
            var path = process.env.CACHE_ROOT_DIR,
                request_url = key.split('#!')[1],
                filename = defaults.fileName;
             
            return path + (request_url || '');
        },
        fileName: config.fileName || '___'
    }
    return{
        init: function() {
            this.cache = cache_manager.caching({
                store: file_cache(defaults)
            });
        },

        beforePhantomRequest: function(req, res, next) {
            if(req.method !== 'GET') {
                return next();
            }

            this.cache.get(req.prerender.url, function (err, result) {
                if (!err && result) {
                    var now = new Date();
                    console.log(now.toDateString() + ' ' + now.toTimeString() + ' cache hit');
                    zlib.inflate(result, function(error, result) {
                        if (!error) {
                            res.send(200, result);
                        }
                    });
                } else {
                    next();
                }
            });
        },

        afterPhantomRequest: function(req, res, next) {
            if (req.prerender.statusCode == 200) {
                this.cache.set(req.prerender.url, req.prerender.documentHTML);
            }
            next();
        }
    }
};<commit_msg>send the prerender-status-code<commit_after>var cache_manager = require('cache-manager'),
    fs = require('node-fs'),
    zlib = require('zlib');

module.exports = function(config){
    var defaults = {
        /**
         * Builds the path where the file are going to be stored
         * uses the default function if no other is provided (config.pathBuilder)
         * @param key String the url of the resource being processed
         * @return path String folder path like '../', 'f1/f2/f3/.../'
         */
        pathBuilder: config.pathBuilder || function(key){
            var path = process.env.CACHE_ROOT_DIR,
                request_url = key.split('#!')[1],
                filename = defaults.fileName;
             
            return path + (request_url || '');
        },
        fileName: config.fileName || '___'
    }
    return{
        init: function() {
            this.cache = cache_manager.caching({
                store: file_cache(defaults)
            });
        },

        beforePhantomRequest: function(req, res, next) {
            if(req.method !== 'GET') {
                return next();
            }

            this.cache.get(req.prerender.url, function (err, result) {
                if (!err && result) {
                    var now = new Date();
                    console.log(now.toDateString() + ' ' + now.toTimeString() + ' cache hit');
                    zlib.inflate(result, function(error, result) {
                        if (!error) {
                            match = /<meta[^<>]*(?:name=['"]prerender-status-code['"][^<>]*content=['"]([0-9]{3})['"]|content=['"]([0-9]{3})['"][^<>]*name=['"]prerender-status-code['"])[^<>]*>/i.exec(String.fromCharCode.apply(null, result));
                            res.send(match[1] || match[2] || 200, result);
                        }
                    });
                } else {
                    next();
                }
            });
        },

        afterPhantomRequest: function(req, res, next) {
            if (req.prerender.statusCode == 200) {
                this.cache.set(req.prerender.url, req.prerender.documentHTML);
            }
            next();
        }
    }
};
{'fraction_non_alphanumeric': 0.1412594213469487, 'fraction_numerical': 0.006807682956479455, 'mean_word_length': 1.44589774078478, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2981392', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1085, 'n_words': 233}