diff options
Diffstat (limited to 'lib/http.js')
-rw-r--r-- | lib/http.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/http.js b/lib/http.js index ea0ce2afc29..3f9d8fcad3d 100644 --- a/lib/http.js +++ b/lib/http.js @@ -292,6 +292,7 @@ function OutgoingMessage (socket) { this.useChunkedEncodingByDefault = true; this._hasBody = true; + this._trailer = ''; this.finished = false; } @@ -484,6 +485,26 @@ OutgoingMessage.prototype.write = function (chunk, encoding) { return ret; }; + +OutgoingMessage.prototype.addTrailers = function (headers) { + this._trailer = ""; + var keys = Object.keys(headers); + var isArray = (Array.isArray(headers)); + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + if (isArray) { + field = headers[key][0]; + value = headers[key][1]; + } else { + field = key; + value = headers[key]; + } + + this._trailer += field + ": " + value + CRLF; + } +}; + + OutgoingMessage.prototype.finish = function () { throw new Error("finish() has been renamed to close()."); }; @@ -520,7 +541,9 @@ OutgoingMessage.prototype.end = function (data, encoding) { + l + CRLF + data - + "\r\n0\r\n\r\n" + + "\r\n0\r\n" + + this._trailer + + "\r\n" , encoding ); } else { @@ -535,7 +558,7 @@ OutgoingMessage.prototype.end = function (data, encoding) { if (!hot) { if (this.chunkedEncoding) { - ret = this._send('0\r\n\r\n'); // Last chunk. + ret = this._send('0\r\n' + this._trailer + '\r\n'); // Last chunk. } else if (!data) { // Force a flush, HACK. ret = this._send(''); |