BotanSS/net/Http.js

49 lines
992 B
JavaScript
Raw Normal View History

2015-04-18 14:14:36 +00:00
var cl = global.botanLoader;
2014-10-10 08:38:06 +00:00
var Dragonfly = global.Dragonfly;
2015-04-18 14:14:36 +00:00
var Cookie = cl.load( "botanss.net.components.Cookie" );
2014-10-10 08:38:06 +00:00
var HTTP = function( req, res )
{
var _self = this;
var canExit = true;
// Simple HTTP Model
this.response = {
statusCode: 200
, headers: {
2015-01-06 07:16:35 +00:00
"Content-Type": "text/html; charset=utf-8"
, "Powered-By": "Botanical Framework (Node.js)"
2014-10-10 08:38:06 +00:00
}
, write: function( str ) { _self.response.content = str }
, writeLine: function( str ) { _self.response.content += str + "\n"; }
, end: function()
{
if( canExit )
{
canExit = false;
var rc = _self.response;
res.writeHead( rc.statusCode, rc.headers );
res.end( rc.content );
}
}
, content: ''
2015-04-15 04:17:21 +00:00
, cookie: new Cookie( "", this )
2014-10-10 08:38:06 +00:00
, raw: res
};
this.request = {
uri: require('url').parse( req.url )
, isPost: ( req.method == 'POST' )
2015-04-15 04:17:21 +00:00
, cookie: new Cookie( req.headers.cookie, this )
2014-10-10 08:38:06 +00:00
, remoteAddr: req.connection.remoteAddress
, raw: req
};
2015-04-15 04:17:21 +00:00
2014-10-10 08:38:06 +00:00
};
module.exports = HTTP;