<commit_before>var http = require('http');
var net = require('net');
var registry = require('etcd-registry');
var pump = require('pump');

var noop = function() {};

var wrap = function(fn) {
	return function(request, response, route) {
		fn(request, route);
	};
};

var router = function(cs, onroute) {
	if (typeof cs === 'function') return router(null, cs);

	var server = http.createServer();
	var services = typeof cs === 'object' && cs ? cs : registry(cs);

	if (onroute.length === 2) onroute = wrap(onroute);

	var lookup = function(list, cb) {
		var i = 0;

		if (!list) return cb();
		if (typeof list === 'object' && list.hostname && list.port) return cb(null, list);
		if (!Array.isArray(list)) list = [list];
		if (!list.length) return cb();

		services.lookup(list[i++], function onservice(err, service) {
			if (err) return cb(err);
			if (service) return cb(null, service);
			if (i >= list.length) return cb();
			services.lookup(list[i++], onservice);
		});
	};

	var proxyConnection = function(request, socket, data, service) {
		server.emit('route', request, service);

		var proxy = net.connect(service.port, service.hostname);
		var head = request.method+' '+request.url+' HTTP/1.1\r\n';

		Object.keys(request.headers).forEach(function(key) {
			head += key+': '+request.headers[key]+'\r\n';
		});

		head += '\r\n';
		proxy.write(head);
		proxy.write(data);

		pump(socket, proxy, socket);
	};

	var proxyRequest = function(request, response, service) {
		server.emit('route', request, service);
		request.emit('route', service);

		var req = http.request({
			method: request.method,
			headers: request.headers,
			path: request.url,
			hostname: service.hostname,
			port: service.port,
			agent: false
		});

		pump(request, req);
		req.on('error', function() {
			request.destroy();
		});
		req.on('response', function(res) {
			response.writeHead(res.statusCode, res.headers);
			pump(res, response);
		});
	};

	var destroyer = function(socket) {
		return function(err, service) {
			if (!service) socket.destroy();
		};
	};
<commit_msg>remove keep-alive headers before proxying<commit_after>var http = require('http');
var net = require('net');
var registry = require('etcd-registry');
var pump = require('pump');

var noop = function() {};

var wrap = function(fn) {
	return function(request, response, route) {
		fn(request, route);
	};
};

var router = function(cs, onroute) {
	if (typeof cs === 'function') return router(null, cs);

	var server = http.createServer();
	var services = typeof cs === 'object' && cs ? cs : registry(cs);

	if (onroute.length === 2) onroute = wrap(onroute);

	var lookup = function(list, cb) {
		var i = 0;

		if (!list) return cb();
		if (typeof list === 'object' && list.hostname && list.port) return cb(null, list);
		if (!Array.isArray(list)) list = [list];
		if (!list.length) return cb();

		services.lookup(list[i++], function onservice(err, service) {
			if (err) return cb(err);
			if (service) return cb(null, service);
			if (i >= list.length) return cb();
			services.lookup(list[i++], onservice);
		});
	};

	var proxyConnection = function(request, socket, data, service) {
		server.emit('route', request, service);

		var proxy = net.connect(service.port, service.hostname);
		var head = request.method+' '+request.url+' HTTP/1.1\r\n';

		Object.keys(request.headers).forEach(function(key) {
			head += key+': '+request.headers[key]+'\r\n';
		});

		head += '\r\n';
		proxy.write(head);
		proxy.write(data);

		pump(socket, proxy, socket);
	};

	var proxyRequest = function(request, response, service) {
		server.emit('route', request, service);
		request.emit('route', service);
		delete request.headers.connection; // fixes ECONNRESET issue

		var req = http.request({
			method: request.method,
			headers: request.headers,
			path: request.url,
			hostname: service.hostname,
			port: service.port,
			agent: false
		});

		pump(request, req);
		req.on('error', function() {
			request.destroy();
		});
		req.on('response', function(res) {
			response.writeHead(res.statusCode, res.headers);
			pump(res, response);
		});
	};

	var destroyer = function(socket) {
		return function(err, service) {
			if (!service) socket.destroy();
		};
	};

{'fraction_non_alphanumeric': 0.18147358445865908, 'fraction_numerical': 0.0018952854773750297, 'mean_word_length': 4.086746987951807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3642031', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1391, 'n_words': 355}