<commit_before>var BufferResponse = require('express-buffer-response');
var onHeaders = require('on-headers');
var pathRegexp = require('path-to-regexp');
var URL = require('url');
//var CacheDebounce = require('cache-debounce');
var debug = require('debug')('raja:express');

module.exports = ExpressProxy;

function ExpressProxy(raja, opts) {
	if (!(this instanceof ExpressProxy)) return new ExpressProxy(raja, opts);
	this.raja = raja;
	this.opts = opts || {};
	this.middleware = this.middleware.bind(this);
}

//var GetMw = CacheDebounce(function(url, baseUrl, req, res, next, cb) {
var GetMw = function(url, baseUrl, req, res, next, cb) {
	var raja = this.raja;
	raja.retrieve(url, req, function(err, resource) {
		if (err) raja.error(err); // fall through
		res.set('X-Raja', raja.opts.namespace);
		if (resource && resource.valid) {
			debug('found valid', resource.key, resource.headers);
			for (var name in resource.headers) {
				if (name in {'Content-Type':1, 'ETag':1, 'Vary':1, 'Content-Encoding':1, 'X-Grant': 1}) {
					res.set(name, resource.headers[name]);
				}
			}
			var ETag = resource.headers.ETag;
			if (ETag && req.get('If-None-Match') == ETag) {
				res.sendStatus(304);
			} else {
				if (resource.mtime) res.set('Last-Modified', resource.mtime.toUTCString());
				res.send(resource.data);
			}
			cb();<commit_msg>Try to get If-Modified-Since right<commit_after>var BufferResponse = require('express-buffer-response');
var onHeaders = require('on-headers');
var pathRegexp = require('path-to-regexp');
var URL = require('url');
//var CacheDebounce = require('cache-debounce');
var debug = require('debug')('raja:express');

module.exports = ExpressProxy;

function ExpressProxy(raja, opts) {
	if (!(this instanceof ExpressProxy)) return new ExpressProxy(raja, opts);
	this.raja = raja;
	this.opts = opts || {};
	this.middleware = this.middleware.bind(this);
}

//var GetMw = CacheDebounce(function(url, baseUrl, req, res, next, cb) {
var GetMw = function(url, baseUrl, req, res, next, cb) {
	var raja = this.raja;
	raja.retrieve(url, req, function(err, resource) {
		if (err) raja.error(err); // fall through
		res.set('X-Raja', raja.opts.namespace);
		if (resource && resource.valid) {
			debug('found valid', resource.key, resource.headers);
			for (var name in resource.headers) {
				if (name in {'Content-Type':1, 'ETag':1, 'Vary':1, 'Content-Encoding':1, 'X-Grant': 1}) {
					res.set(name, resource.headers[name]);
				}
			}
			var ETag = resource.headers.ETag;
			if (ETag && req.get('If-None-Match') == ETag) {
				res.sendStatus(304);
			} else {
				if (resource.mtime) {
					var utcTime = resource.mtime.toUTCString();
					var modSince = req.get('If-Modified-Since');
					if (!modSince || modSince == utcTime) {
						res.set('Last-Modified', utcTime);
					}
				}
				res.send(resource.data);
			}
			cb();
{'fraction_non_alphanumeric': 0.17653239929947462, 'fraction_numerical': 0.005604203152364273, 'mean_word_length': 4.136690647482014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '199762', 'n_tokens_mistral': 1100, 'n_tokens_neox': 985, 'n_words': 223}