Node.js: buffering HTTP headers before writing the body.
This commit is contained in:
@@ -178,21 +178,16 @@ function writeHead(statusCode, reason, obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unit_lib.unit_response_headers(this, statusCode, this.headers, this.headers_count, this.headers_len);
|
|
||||||
|
|
||||||
this.headersSent = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
|
ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
|
||||||
var contentLength = 0;
|
var contentLength = 0;
|
||||||
|
|
||||||
if (!this.headersSent) {
|
if (!this.headersSent) {
|
||||||
this.writeHead(this.statusCode);
|
unit_lib.unit_response_headers(this, this.statusCode, this.headers,
|
||||||
}
|
this.headers_count, this.headers_len);
|
||||||
|
|
||||||
if (this.finished) {
|
this.headersSent = true;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof chunk === 'function') {
|
if (typeof chunk === 'function') {
|
||||||
@@ -225,15 +220,23 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ServerResponse.prototype.write = function write(chunk, encoding, callback) {
|
ServerResponse.prototype.write = function write(chunk, encoding, callback) {
|
||||||
|
if (this.finished) {
|
||||||
|
throw new Error("Write after end");
|
||||||
|
}
|
||||||
|
|
||||||
this._writeBody(chunk, encoding, callback);
|
this._writeBody(chunk, encoding, callback);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
ServerResponse.prototype.end = function end(chunk, encoding, callback) {
|
ServerResponse.prototype.end = function end(chunk, encoding, callback) {
|
||||||
|
if (!this.finished) {
|
||||||
this._writeBody(chunk, encoding, callback);
|
this._writeBody(chunk, encoding, callback);
|
||||||
|
|
||||||
|
unit_lib.unit_response_end(this);
|
||||||
|
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user