BotanSS/net/components/Cookie.js

44 lines
758 B
JavaScript
Raw Normal View History

2016-02-12 21:03:21 +00:00
"use strict";
2015-04-15 04:17:21 +00:00
2016-02-12 21:03:21 +00:00
var cl = global.botanLoader;
2015-07-23 09:15:24 +00:00
var WebParam = cl.load( "botanss.utils.WebParam" );
2015-04-15 04:17:21 +00:00
2016-02-12 21:03:21 +00:00
class Cookie extends WebParam
2015-04-15 04:17:21 +00:00
{
2016-02-12 21:03:21 +00:00
constructor( cookieStr, HTTP )
{
super( cookieStr );
this.HTTP = HTTP;
}
2015-04-15 04:17:21 +00:00
2016-02-12 21:03:21 +00:00
seth( name, value )
{
this.set( name, value );
this.HTTP.response.headers[ "Set-Cookie" ] = this.toString();
}
2015-04-15 04:17:21 +00:00
2016-02-12 21:03:21 +00:00
toString()
2015-07-23 09:15:24 +00:00
{
2016-02-12 21:03:21 +00:00
var cookieStr = "";
var p = "";
var e = "";
for( var i in this.param )
2015-07-23 09:15:24 +00:00
{
2016-02-12 21:03:21 +00:00
switch( i.toLowerCase() )
{
case "path":
p = this.param[i];
continue;
case "expires":
e = this.param[i];
continue;
}
cookieStr += i + "=" + this.param[i] + ";";
2015-07-23 09:15:24 +00:00
}
2016-02-12 21:03:21 +00:00
cookieStr += "Path=" + p + ";" + ( e ? ( " Expires=" + e + ";" ) : "" );
return cookieStr;
2015-07-23 09:15:24 +00:00
}
2016-02-12 21:03:21 +00:00
}
2015-04-15 04:17:21 +00:00
module.exports = Cookie;