Skip to content

Commit

Permalink
buffer is a real Buffer now. Encode to a string (for json, etc) late …
Browse files Browse the repository at this point in the history
…as possible… not right in the response
  • Loading branch information
technoweenie committed Nov 2, 2011
1 parent d6b71ba commit 96fe3eb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/http_client.coffee
Expand Up @@ -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 = ''

Expand All @@ -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
Expand All @@ -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', =>

Expand Down

0 comments on commit 96fe3eb

Please sign in to comment.