diff options
author | isaacs <i@izs.me> | 2013-04-08 19:46:51 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-04-08 20:33:56 +0400 |
commit | e4b716efaa00f34fe4d9f1c141c93e2aa994328c (patch) | |
tree | 63286e67e13efac3baf3377f66bda0d024e38d89 /lib | |
parent | 037bcac7ba0b10dac87538e2e6b7cc2177624039 (diff) |
http: Support write(data, 'hex')
We were assuming that any string can be concatenated safely to
CRLF. However, for hex, base64, or binary encoded writes, this
is not the case, and results in sending the incorrect response.
An unusual edge case, but certainly a bug.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/http.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/http.js b/lib/http.js index b4fc2add113..ac6b1c6bf7a 100644 --- a/lib/http.js +++ b/lib/http.js @@ -772,15 +772,18 @@ OutgoingMessage.prototype.write = function(chunk, encoding) { var len, ret; if (this.chunkedEncoding) { - if (typeof(chunk) === 'string') { + if (typeof(chunk) === 'string' && + encoding !== 'hex' && + encoding !== 'base64' && + encoding !== 'binary') { len = Buffer.byteLength(chunk, encoding); chunk = len.toString(16) + CRLF + chunk + CRLF; ret = this._send(chunk, encoding); } else { - // buffer + // buffer, or a non-toString-friendly encoding len = chunk.length; this._send(len.toString(16) + CRLF); - this._send(chunk); + this._send(chunk, encoding); ret = this._send(CRLF); } } else { |