Skip to content

Commit

Permalink
Remove _prepareData
Browse files Browse the repository at this point in the history
  • Loading branch information
akaspin committed Oct 31, 2010
1 parent f9638e7 commit 000cfae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@
*kaph* does not interfere in node.js API. All that *kaph* do is two exports for
simplify response flow control:

var sys = require("sys");
var util = require("util");
var http = require("http");
var kaph = require("kaph");

Expand Down
43 changes: 22 additions & 21 deletions index.js
Expand Up @@ -32,6 +32,18 @@ function Handler(request, response, args) {
}
exports.Handler = Handler;

/**
* Cleans response.
*/
Handler.prototype.clear = function() {
this._headers = {
"Server": "node.js:" + process.version,
"Content-Type": "text/html; charset=UTF-8"
};
this._statusCode = 200;
this._encoding = 'utf8';
};

// Supported methods
Handler.prototype._supportedMethods =
['HEAD', 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'];
Expand Down Expand Up @@ -129,20 +141,21 @@ Handler.prototype.sendHeaders = function() {
/**
* Writes data to client.
* If headers not sent - sends they first.
* @param data
* @param encoding
* @param {Buffer||String} Data chunk. If no data - nothing happens.
* @param {String} encoding
*/
Handler.prototype.write = function(data, encoding) {
if (!data || data == null) return; // If no data - do nothing

if (!this._headersWritten) {
this.sendHeaders();
}
// if (data instanceof Object) {
// this.setHeader("Content-Type", "text/javascript; charset=UTF-8");
// data = JSON.stringify(data);
// }

this.response.write((data == undefined ? "" : data.toString()),
(encoding || this._encoding));

this.response.write(data, (encoding || this._encoding));
};

/**
Expand Down Expand Up @@ -173,15 +186,14 @@ Handler.prototype.end = function(data, encoding) {

// and content length
if (!("Content-Length" in this._headers)) {
var l = this._encoding == 'utf8' ?
Buffer.byteLength(data, 'utf8') :
data.length;
var l = Buffer.isBuffer(data) ? data.length
: Buffer.byteLength(data, encoding || this._encoding);
this.setHeader("Content-Length", l);
}
}
this.sendHeaders();
}
this.response.end(data, (encoding || this._encoding));
this.response.end(data, encoding || this._encoding);
};

/**
Expand Down Expand Up @@ -255,21 +267,10 @@ Handler.prototype._summary = function() {
return this.request.method + " " + this.request.url;
};

/**
* Cleans response.
*/
Handler.prototype.clear = function() {
this._headers = {
"Server": "node.js:" + process.version,
"Content-Type": "text/html; charset=UTF-8"
};
this._statusCode = 200;
this._encoding = 'utf8';
};

/**
* HTTP Error
* @constructor
* @extends Error
* @param code Status code
* @param reason Reason
*/
Expand Down

0 comments on commit 000cfae

Please sign in to comment.