<commit_before>/**
* Server is a .net executable written in js, compiled to .net using jsc
*/
import System;
import System.Net;
import System.IO;

var http = {};

class HttpServer {

var httpListener : HttpListener;
var prefix;

function HttpServer( prefix ) {
	var httpListener : HttpListener = new HttpListener();
	this.httpListener = httpListener;
	this.prefix = prefix;
	httpListener.Prefixes.Add( prefix );
	// return this;
}

function ListenerCallback( result : IAsyncResult ) : void {
	// print( 'ListenerCallback():' );
}

// doesn't work because member vars can't hold functions for some reason.
// var ListenerCallback : Function = function( result: IAsyncResult ) { print( 'ListenerCallback():' ); };

function listen() {
	print( 'HttpServer.listen():' );
	this.httpListener.Start();
	print( 'listener started successfully' );
	print( 'httpListener: ' + this.httpListener );
	var result : IAsyncResult = this.httpListener.BeginGetContext( new AsyncCallback( this.ListenerCallback ), httpListener );
	print( 'BeginGetContext called successfully' );
}
} // class

/*
Non working solution for Async callback
var _ListenerCallback = function( result : IAsyncResult ) {
	print( 'ListenerCallback():' );
}
var ListenerCallback : AsyncCallback = AsyncCallback( _ListenerCallback );
*/

http.createServer = function( request_listener, prefix ) {
	return new HttpServer( prefix );
}

// takes a .js file on the commandline, eval it 
var args : String[] = Environment.GetCommandLineArgs();
var sr : StreamReader = new StreamReader( args[1] );
var script = sr.ReadToEnd();
eval( script, 'unsafe' );
sr.Close();<commit_msg>callback function and basic http response working<commit_after>/**
* Server is a .net executable written in js, compiled to .net using jsc
*/
import System;
import System.Threading;
import System.Net;
import System.IO;

var http = {};

class HttpServer 
{
	var httpListener : HttpListener;
	var prefix;

	function HttpServer( prefix ) {
		var httpListener : HttpListener = new HttpListener();
		this.httpListener = httpListener;
		this.prefix = prefix;
		httpListener.Prefixes.Add( prefix );
		// return this;
	}

	function listen() {
		print( 'HttpServer.listen():' );
		this.httpListener.Start();
		print( 'listener started successfully' );
		print( 'httpListener: ' + this.httpListener );
		var result : IAsyncResult = this.httpListener.BeginGetContext( ListenerCallback, httpListener );
		print( 'BeginGetContext called successfully' );
		Thread.Sleep( Timeout.Infinite );
	}
	function ListenerCallback( result : IAsyncResult ) {
		print( 'ListenerCallback():' );
		var listener : HttpListener = HttpListener( result.AsyncState );
		var context : HttpListenerContext = listener.EndGetContext( result );
		var request : HttpListenerRequest = context.Request;
		var response : HttpListenerResponse = context.Response;
		var responseString : String = "<HTML><BODY> Hello world!</BODY></HTML>";
		var buffer : byte[] = System.Text.Encoding.UTF8.GetBytes( responseString );
		response.ContentLength64 = buffer.Length;
		var output : Stream = response.OutputStream;
		output.Write( buffer,0,buffer.Length );
		output.Close();
	}

} // class

http.createServer = function( callback, prefix ) {
	return new HttpServer( prefix );
}

// takes a .js file on the commandline, eval it 
var args : String[] = Environment.GetCommandLineArgs();
var sr : StreamReader = new StreamReader( args[1] );
var script = sr.ReadToEnd();
eval( script, 'unsafe' );
sr.Close();
{'fraction_non_alphanumeric': 0.1234887737478411, 'fraction_numerical': 0.0017271157167530224, 'mean_word_length': 4.706075533661741, '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': '3125045', 'n_tokens_mistral': 1022, 'n_tokens_neox': 983, 'n_words': 303}