<commit_before>/*
 * server.js: Simple server for receiving log files from the Surface Foliage application.
 *
 * (C) 2010 <NAME>
 *
 */

var http = require('http')
  , sys = require('sys')
  , querystring = require('querystring')
  , url = require('url')
  , path = require('path')
  , fs = require('fs');

require.paths.unshift(path.join(__dirname, "/lib/proto/lib"));
require('proto');

var pathExpression = /^(\/[^\/]+)(.*)$/;

var server = http.createServer(function (request, response) {
	var httpParams = querystring.parse(request.body);
	httpParams.mixin(url.parse(request.url));
	request.params = httpParams;

	if ('/' !== request.url) {
	  var path = request.url.match(pathExpression);
	}
	else {
	  var path = ['/', '/', ''];
	}
	
	response.writeHead(200, {'Content-Type': 'text/plain'});
  response.write('Foliage Remote Serving Request for: ' + path[1]);
	
	switch(path[1]) {
		case '/log' :
		  var now = new Date().getTime();
		  var logFile = __dirname + '/session-logs/session-log-' + now + '.json';
		  response.write("\n\nApplication path: " + __dirname);
		  response.write('\n\nSaving log data to: ' + logFile + ' ...');
			var postData = ''; 

		  request.addListener("data", function (chunk) {
			  postData += chunk;
	    });
	
	    request.addListener("end", function () {
		    if(postData && postData.length > 0) {
		      fs.open(logFile, "w+", 0644, function (error, fd) {
			    	if (error) throw error;
					
					  fs.writeSync(fd, postData, 0, 'ascii');
				    response.write('\n\nLog data saved successfully');
					  response.write('\n\nLog Data: \n' + postData);
		      	response.end();
		    	});
				}
			  else { 
				  response.write('\n\nNo data to log. Cancelled log operation.');
				  response.end();
				}
	    });
		  break;
		
		case '/ping' :
		  response.write('\n \nFoliage Remote Operational');
			response.end();
		  break;
		
		default : 
		  response.end();
		  break;
	}
}).listen(80);<commit_msg>Removed path logging in response as thats probably a bad idea in production<commit_after>/*
 * server.js: Simple server for receiving log files from the Surface Foliage application.
 *
 * (C) 2010 <NAME>
 *
 */

var http = require('http')
  , sys = require('sys')
  , querystring = require('querystring')
  , url = require('url')
  , path = require('path')
  , fs = require('fs');

require.paths.unshift(path.join(__dirname, "/lib/proto/lib"));
require('proto');

var pathExpression = /^(\/[^\/]+)(.*)$/;

var server = http.createServer(function (request, response) {
	var httpParams = querystring.parse(request.body);
	httpParams.mixin(url.parse(request.url));
	request.params = httpParams;

	if ('/' !== request.url) {
	  var path = request.url.match(pathExpression);
	}
	else {
	  var path = ['/', '/', ''];
	}
	
	response.writeHead(200, {'Content-Type': 'text/plain'});
  response.write('Foliage Remote Serving Request for: ' + path[1]);
	
	switch(path[1]) {
		case '/log' :
		  var now = new Date().getTime();
		  var logFile = __dirname + '/session-logs/session-log-' + now + '.json';
		  //response.write("\n\nApplication path: " + __dirname);
		  //response.write('\n\nSaving log data to: ' + logFile + ' ...');
			var postData = ''; 

		  request.addListener("data", function (chunk) {
			  postData += chunk;
	    });
	
	    request.addListener("end", function () {
		    if(postData && postData.length > 0) {
		      fs.open(logFile, "w+", 0644, function (error, fd) {
			    	if (error) throw error;
					
					  fs.writeSync(fd, postData, 0, 'ascii');
				    response.write('\n\nLog data saved successfully');
					  response.write('\n\nLog Data: \n' + postData);
		      	response.end();
		    	});
				}
			  else { 
				  response.write('\n\nNo data to log. Cancelled log operation.');
				  response.end();
				}
	    });
		  break;
		
		case '/ping' :
		  response.write('\n \nFoliage Remote Operational');
			response.end();
		  break;
		
		default : 
		  response.end();
		  break;
	}
}).listen(80);
{'fraction_non_alphanumeric': 0.18470055359838952, 'fraction_numerical': 0.008555611474584801, 'mean_word_length': 2.8932419196865817, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5055280', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1301, 'n_words': 291}