New class conditional stream
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
var cl = global.botanLoader;
 | 
			
		||||
var Dragonfly = global.Dragonfly;
 | 
			
		||||
var CondStream = cl.load( "botanss.utils.CondStream" );
 | 
			
		||||
 | 
			
		||||
var FatalError = cl.load( "botanss.errors.FatalError" );
 | 
			
		||||
 | 
			
		||||
@@ -63,14 +64,15 @@ Framework.prototype.run = function()
 | 
			
		||||
	var method = "GET";
 | 
			
		||||
	if( this.HTTP.request.isPost )
 | 
			
		||||
	{
 | 
			
		||||
		this.HTTP.request.raw.addListener( "data", function( data )
 | 
			
		||||
		{
 | 
			
		||||
			_self.requestStr += data.toString();
 | 
			
		||||
		})
 | 
			
		||||
		this.HTTP.request.raw.addListener( "end", function()
 | 
			
		||||
		{
 | 
			
		||||
			_self.parseResult();
 | 
			
		||||
		});
 | 
			
		||||
		_self.requestStr = new CondStream( "/tmp/", 2048 );
 | 
			
		||||
 | 
			
		||||
		this.HTTP.request.raw.addListener(
 | 
			
		||||
			"data" , ( x ) => _self.requestStr.write( x )
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		this.HTTP.request.raw.addListener(
 | 
			
		||||
			"end", () => _self.requestStr.end( () => _self.parseResult() )
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		method = "POST";
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,48 +1,16 @@
 | 
			
		||||
var encodeCookie = function( cookie )
 | 
			
		||||
{
 | 
			
		||||
	var cookieStr = "";
 | 
			
		||||
	var p = "";
 | 
			
		||||
	var e = "";
 | 
			
		||||
	for( var i in cookie )
 | 
			
		||||
	{
 | 
			
		||||
		switch( i.toLowerCase() )
 | 
			
		||||
		{
 | 
			
		||||
			case "path":
 | 
			
		||||
				p = cookie[i];
 | 
			
		||||
				continue;
 | 
			
		||||
			case "expires":
 | 
			
		||||
				e = cookie[i];
 | 
			
		||||
				continue;
 | 
			
		||||
		}
 | 
			
		||||
		cookieStr += i + "=" + cookie[i] + ";";
 | 
			
		||||
	}
 | 
			
		||||
var cl = global.botanLoader;
 | 
			
		||||
 | 
			
		||||
	// Path at tail
 | 
			
		||||
	cookieStr += "Path=" + p + ";" + " Expires=" + e + ";";
 | 
			
		||||
 | 
			
		||||
	return cookieStr; 
 | 
			
		||||
};
 | 
			
		||||
var util = require( "util" );
 | 
			
		||||
 | 
			
		||||
var WebParam = cl.load( "botanss.utils.WebParam" );
 | 
			
		||||
 | 
			
		||||
var Cookie = function( cookieStr, HTTP )
 | 
			
		||||
{
 | 
			
		||||
	var list = {};
 | 
			
		||||
 | 
			
		||||
	cookieStr && cookieStr.split( ";" ).forEach( function( cookie )
 | 
			
		||||
	{
 | 
			
		||||
		var parts = cookie.split( "=" );
 | 
			
		||||
		list[ parts.shift().trim() ] = decodeURI( parts.join( "=" ) );
 | 
			
		||||
	} );
 | 
			
		||||
 | 
			
		||||
	this.__cookie = list;
 | 
			
		||||
 | 
			
		||||
	WebParam.call( this, cookieStr );
 | 
			
		||||
	this.HTTP = HTTP;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Cookie.prototype.set = function( name, value )
 | 
			
		||||
{
 | 
			
		||||
	this.__cookie[ name ] = value;
 | 
			
		||||
};
 | 
			
		||||
util.inherits( Cookie, WebParam );
 | 
			
		||||
 | 
			
		||||
Cookie.prototype.seth = function( name, value )
 | 
			
		||||
{
 | 
			
		||||
@@ -50,15 +18,26 @@ Cookie.prototype.seth = function( name, value )
 | 
			
		||||
	this.HTTP.response.headers[ "Set-Cookie" ] = this.toString();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Cookie.prototype.get = function( name )
 | 
			
		||||
{
 | 
			
		||||
	return this.__cookie[ name ];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Cookie.prototype.toString = function()
 | 
			
		||||
{
 | 
			
		||||
	return encodeCookie( this.__cookie );
 | 
			
		||||
	var cookieStr = "";
 | 
			
		||||
	var p = "";
 | 
			
		||||
	var e = "";
 | 
			
		||||
	for( var i in this.param )
 | 
			
		||||
	{
 | 
			
		||||
		switch( i.toLowerCase() )
 | 
			
		||||
		{
 | 
			
		||||
			case "path":
 | 
			
		||||
				p = this.param[i];
 | 
			
		||||
				continue;
 | 
			
		||||
			case "expires":
 | 
			
		||||
				e = this.param[i];
 | 
			
		||||
				continue;
 | 
			
		||||
		}
 | 
			
		||||
		cookieStr += i + "=" + this.param[i] + ";";
 | 
			
		||||
	}
 | 
			
		||||
	cookieStr += "Path=" + p + ";" + " Expires=" + e + ";";
 | 
			
		||||
	return cookieStr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
module.exports = Cookie;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user