Update http2 for new stream API
This commit is contained in:
parent
264a67aed2
commit
b07f2e25f4
@ -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++) {
|
||||
|
41
lib/http2.js
41
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user