Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

buffer is a real Buffer now. Encode to a string (for json, etc) late …

…as possible… not right in the response
  • Loading branch information...
commit 96fe3ebedfceb3204448aca687878fe1ab60f584 1 parent d6b71ba
@technoweenie technoweenie authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/http_client.coffee
View
11 src/http_client.coffee
@@ -232,9 +232,9 @@ class HttpClient extends Client
# we don't want to carry this around in a Meta
delete meta.agent
- response.setEncoding meta.responseEncoding
-
- buffer = ''
+ size = parseInt response.headers['content-length']
+ bytesRead = 0
+ buffer = new Buffer size
firstChunk = false
tempBuffer = ''
@@ -243,7 +243,7 @@ class HttpClient extends Client
if meta._emitter
unless firstChunk # only buffer the first chunk, the rest will be emitted
- buffer += chunk
+ buffer = chunk
firstChunk = true
else
@@ -262,7 +262,8 @@ class HttpClient extends Client
@emit 'clientError', err
else
- buffer += chunk
+ chunk.copy buffer, bytesRead, 0
+ bytesRead += chunk.length
response.on 'end', =>
Please sign in to comment.
Something went wrong with that request. Please try again.