<commit_before>/**
 * ...
 * @author <NAME>
 */

package nodejs.ufront.web.context;
import thx.error.NotImplemented; 
import js.Node;
import thx.error.Error; 
using StringTools;

class HttpResponse extends ufront.web.context.HttpResponse {

	var res:js.node.http.ServerResponse;
	
	public function new( res:js.node.http.ServerResponse ) {
		super();
		this.res = res;
	}
	
	override function flush() {
		if ( _flushed )
			return;
		
		_flushed = true;
		
		// Set HTTP status code
		res.statusCode = status;
		
		// Set Cookies
		try {
			var cookieHeader = [
				for ( cookie in _cookies ) '${cookie.name}=${cookie.description()}'
			];
			res.setHeader( "Set-Cookie", cookieHeader );
		}
		catch ( e:Dynamic ) {
			throw new Error( "Cannot flush cookies on response, output already sent" );
		}
		
		// Write headers
		for ( key in _headers.keys() ) {
			var val = _headers.get(key);
			if ( key=="Content-type" && null!=charset && val.startsWith('text/') ) {
				val += "; charset=" + charset;
			}
			try {
				res.setHeader(key, val);
			}
			catch ( e:Dynamic ) {
				throw new Error( "Invalid header: '{0}: {1}', or output already sent", [key,val] );
			}
		}

		// Write response content
		res.write( _buff.toString() );
	}
}<commit_msg>Use res.end() to be sure - the request has been dealt with.<commit_after>/**
 * ...
 * @author <NAME>
 */

package nodejs.ufront.web.context;
import thx.error.NotImplemented; 
import js.Node;
import thx.error.Error; 
using StringTools;

class HttpResponse extends ufront.web.context.HttpResponse {

	var res:js.node.http.ServerResponse;
	
	public function new( res:js.node.http.ServerResponse ) {
		super();
		this.res = res;
	}
	
	override function flush() {
		if ( _flushed )
			return;
		
		_flushed = true;
		
		// Set HTTP status code
		res.statusCode = status;
		
		// Set Cookies
		try {
			var cookieHeader = [
				for ( cookie in _cookies ) '${cookie.name}=${cookie.description()}'
			];
			res.setHeader( "Set-Cookie", cookieHeader );
		}
		catch ( e:Dynamic ) {
			throw new Error( "Cannot flush cookies on response, output already sent" );
		}
		
		// Write headers
		for ( key in _headers.keys() ) {
			var val = _headers.get(key);
			if ( key=="Content-type" && null!=charset && val.startsWith('text/') ) {
				val += "; charset=" + charset;
			}
			try {
				res.setHeader(key, val);
			}
			catch ( e:Dynamic ) {
				throw new Error( "Invalid header: '{0}: {1}', or output already sent", [key,val] );
			}
		}

		// Write response content
		res.end( _buff.toString() );
	}
}
{'fraction_non_alphanumeric': 0.152602523659306, 'fraction_numerical': 0.0015772870662460567, 'mean_word_length': 2.921174652241113, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7580569', 'n_tokens_mistral': 991, 'n_tokens_neox': 845, 'n_words': 220}