<commit_before>var BufferRes = require('../');
var expect = require('expect.js');
var fs = require('fs');
var express = require('express');
var session = require('express-session')
var path = require('path');
var http = require('http');


var testFile = path.join(__dirname, 'test.txt');
var ff = [];
var i=0;
while (i++ < 10) ff.push('some text');
ff = ff.join(' ');
fs.writeFileSync(testFile, ff);

var app = express();

var sessionMw = session({
	secret: 'keyboard cat',
	resave: false,
	saveUninitialized: true
});

function cacheMw(req, res, next) {
	BufferRes(res, function(err, buf) {
		expect(res.statusCode).to.be(200);
		if (req.url == '/a') {
			expect(buf.toString()).to.be('{"mykey":"myval"}');
		}
		if (req.url == "/b") {
			expect(buf.length).to.be(ff.length);
		}
		if (req.url == "/c") {
			expect(buf.toString()).to.be("lujon");
		}
	});
	next();
}

var count = 0;

setTimeout(process.exit, 1000);

app.get('/a', cacheMw, function(req, res, next) {
	res.send({mykey: "myval"});
	count++;
});
app.get('/b', cacheMw, function(req, res, next) {
	res.sendFile(testFile);
	count++;
});
app.get('/c', sessionMw, cacheMw, function(req, res, next) {
	res.send("lujon");
	count++;
});

var port = app.listen().address().port;

http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/c');

process.on('exit', function() {
	try {
		fs.unlinkSync(testFile);
	} catch(e) {}

	expect(count).to.be(7);
});
<commit_msg>Add test for aborted request status<commit_after>var BufferRes = require('../');
var expect = require('expect.js');
var fs = require('fs');
var express = require('express');
var session = require('express-session')
var path = require('path');
var http = require('http');


var testFile = path.join(__dirname, 'test.txt');
var ff = [];
var i=0;
while (i++ < 10) ff.push('some text');
ff = ff.join(' ');
fs.writeFileSync(testFile, ff);

var app = express();

var sessionMw = session({
	secret: 'keyboard cat',
	resave: false,
	saveUninitialized: true
});

function cacheMw(req, res, next) {
	BufferRes(res, function(err, buf) {
		if (req.url == '/a') {
			expect(res.statusCode).to.be(200);
			expect(buf.toString()).to.be('{"mykey":"myval"}');
		} else if (req.url == "/b") {
			expect(res.statusCode).to.be(200);
			expect(buf.length).to.be(ff.length);
		} else if (req.url == "/c") {
			expect(res.statusCode).to.be(200);
			expect(buf.toString()).to.be("lujon");
		} else if (req.url == "/d") {
			expect(res.statusCode).to.be(0);
			expect(buf).to.be(null);
		}
	});
	next();
}

var count = 0;

setTimeout(process.exit, 1000);

app.get('/a', cacheMw, function(req, res, next) {
	res.send({mykey: "myval"});
	count++;
});
app.get('/b', cacheMw, function(req, res, next) {
	res.sendFile(testFile);
	count++;
});
app.get('/c', sessionMw, cacheMw, function(req, res, next) {
	res.send("lujon");
	count++;
});
app.get('/d', cacheMw, function(req, res, next) {
	setTimeout(function() {
		res.send("not received by request");
		count++;
	}, 300);
});

var port = app.listen().address().port;

http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/a');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/b');
http.get('http://localhost:' + port + '/c');

var req = http.get('http://localhost:' + port + '/d').on('error', function(e) {
	// catch this expected error
});
setTimeout(function() {
	req.abort();
}, 100);

process.on('exit', function() {
	try {
		fs.unlinkSync(testFile);
	} catch(e) {}

	expect(count).to.be(8);
});

{'fraction_non_alphanumeric': 0.24883238194084067, 'fraction_numerical': 0.009600415153087702, 'mean_word_length': 4.324585635359116, 'pattern_counts': {'":': 2, '<': 5, '<?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': '5059620', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1426, 'n_words': 300}