<commit_before>var Transform = require('pipestream').Transform;
var config = require('../../util').config;
var protocolLength = 'weinre://'.length;

function getWeinreScript(name) {
	return '<script src="http://weinre.' + config.localUIHost + '/target/target-script-min.js#'
	+ name + '"></script>';
}

module.exports = function(req, res, next) {
	if (req.rules.weinre) {
		res.on('src', function(_res) {
			var url = req.rules.weinre.url.substring(protocolLength);
			if (url) {
				var transform = new Transform();
				transform._transform = function(chunk, encoding, callback) {
					if (!chunk) {
						chunk = getWeinreScript(url);
					}
					callback(null, encoding);
				};
				if (util.supportHtmlTransform(_res)) {
					res.addZipTransform(transform, false, true);
				}
			}
		});
	}
	
	next();
};<commit_msg>add weinre<commit_after>var Transform = require('pipestream').Transform;
var util = require('../../util');
var config = util.config;
var protocolLength = 'weinre://'.length;

function getWeinreScript(name) {
	return '<script src="http://weinre.' + config.localUIHost + '/target/target-script-min.js#'
	+ name + '"></script>';
}

module.exports = function(req, res, next) {
	if (req.rules.weinre) {
		res.on('src', function(_res) {
			if (!util.supportHtmlTransform(_res)) {
				return;
			}
			var url = req.rules.weinre.url.substring(protocolLength);
			if (!url) {
				return;
			}
			
			var transform = new Transform();
			transform._transform = function(chunk, encoding, callback) {
				if (!chunk) {
					chunk = getWeinreScript(url);
				}
				callback(null, encoding);
			};
			
			res.addZipTransform(transform, false, true);
		
		});
	}
	
	next();
};
{'fraction_non_alphanumeric': 0.1761904761904762, 'fraction_numerical': 0.0, 'mean_word_length': 3.5188172043010755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '205168', 'n_tokens_mistral': 658, 'n_tokens_neox': 551, 'n_words': 108}