diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 9025e5d940..2f80b43ff6 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -1,10 +1,7 @@ path = require("path"); -libDir = path.join(path.dirname(__filename), "../lib"); -require.paths.unshift(libDir); - -var puts = require("sys").puts; -http = require("http"); +var puts = require("../lib/sys").puts; +http = require("../lib/http2"); fixed = "" for (var i = 0; i < 20*1024; i++) { diff --git a/lib/http2.js b/lib/http2.js index 770bd6611d..8b26a3f1b6 100644 --- a/lib/http2.js +++ b/lib/http2.js @@ -111,7 +111,7 @@ function OutgoingMessage () { 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) { @@ -139,7 +139,7 @@ OutgoingMessage.prototype.send = function (data, encoding) { 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; @@ -197,19 +197,19 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) { 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) { @@ -219,12 +219,17 @@ OutgoingMessage.prototype.sendBody = function (chunk, encoding) { } }; +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(); }; @@ -241,10 +246,16 @@ function ServerResponse (req) { 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()'); }; @@ -259,7 +270,7 @@ function ClientRequest (method, url, headers) { } 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; @@ -282,7 +293,7 @@ function flushMessageQueue (socket, queue) { var data = message.output.shift(); var encoding = message.outputEncodings.shift(); - socket.send(data, encoding); + socket.write(data, encoding); } if (!message.finished) break;