diff options
author | Mark Nottingham <mnot@mnot.net> | 2010-09-09 10:29:35 +0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-09-15 02:20:45 +0400 |
commit | 4fe3007a1ae4c35e18d297af3151eb51d0458859 (patch) | |
tree | 24447426383f8759d8d3b6461141829262ccbae6 /lib/http.js | |
parent | 83ff473d30c45baa2c975793a7ffee06f19e0b3b (diff) |
Support for outgoing HTTP trailing headers
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(''); |