sys.inherits(OutgoingMessage, events.EventEmitter);
exports.OutgoingMessage = OutgoingMessage;
-OutgoingMessage.prototype.send = function (data, encoding) {
+OutgoingMessage.prototype._send = function (data, encoding) {
var length = this.output.length;
if (length === 0) {
this.outputEncodings.push(encoding);
};
-OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) {
+OutgoingMessage.prototype._sendHeaderLines = function (first_line, headers) {
var sentConnectionHeader = false;
var sendContentLengthHeader = false;
var sendTransferEncodingHeader = false;
messageHeader += CRLF;
- this.send(messageHeader);
+ this._send(messageHeader);
// wait until the first body chunk, or finish(), is sent to flush.
};
-OutgoingMessage.prototype.sendBody = function (chunk, encoding) {
+OutgoingMessage.prototype.write = function (chunk, encoding) {
encoding = encoding || "ascii";
if (this.chunkEncoding) {
- this.send(process._byteLength(chunk, encoding).toString(16));
- this.send(CRLF);
- this.send(chunk, encoding);
- this.send(CRLF);
+ this._send(process._byteLength(chunk, encoding).toString(16));
+ this._send(CRLF);
+ this._send(chunk, encoding);
+ this._send(CRLF);
} else {
- this.send(chunk, encoding);
+ this._send(chunk, encoding);
}
if (this.flushing) {
}
};
+OutgoingMessage.prototype.sendBody = function () {
+ throw new Error('sendBody() renamed to write()');
+};
+
+
OutgoingMessage.prototype.flush = function () {
this.emit("flush");
};
-OutgoingMessage.prototype.finish = function () {
- if (this.chunkEncoding) this.send("0\r\n\r\n"); // last chunk
+OutgoingMessage.prototype.close = function () {
+ if (this.chunkEncoding) this._send("0\r\n\r\n"); // last chunk
this.finished = true;
this.flush();
};
sys.inherits(ServerResponse, OutgoingMessage);
exports.ServerResponse = ServerResponse;
-ServerResponse.prototype.sendHeader = function (statusCode, headers) {
+ServerResponse.prototype.writeHead = function (statusCode, headers) {
var reason = STATUS_CODES[statusCode] || "unknown";
var status_line = "HTTP/1.1 " + statusCode.toString() + " " + reason + CRLF;
- this.sendHeaderLines(status_line, headers);
+ this._sendHeaderLines(status_line, headers);
+};
+
+ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead;
+
+ServerResponse.prototype.sendHeader = function () {
+ throw new Error('sendHeader renamed to writeHead()');
};
}
this.closeOnFinish = true;
- this.sendHeaderLines(method + " " + url + " HTTP/1.1\r\n", headers);
+ this._sendHeaderLines(method + " " + url + " HTTP/1.1\r\n", headers);
}
sys.inherits(ClientRequest, OutgoingMessage);
exports.ClientRequest = ClientRequest;
var data = message.output.shift();
var encoding = message.outputEncodings.shift();
- socket.send(data, encoding);
+ socket.write(data, encoding);
}
if (!message.finished) break;