Skip to content

Commit

Permalink
empty GET responses should not return undefined but ""
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Treacy committed Mar 3, 2011
1 parent 309ab7b commit 512b3ea
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/http_client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ class HttpClient extends Client
err.message = undefined if meta.statusCode is 404 # message == undefined to be in sync with pbc
err.statusCode = meta.statusCode # handier access to the HTTP status in case of an error
err
else @decodeBuffer(buffer, meta)
else @decodeBuffer(buffer, meta, verb)

if meta.statusCode is 300 and meta.contentType.match /^multipart\/mixed/ # multiple choices
boundary = Utils.extractBoundary meta.contentType
buffer = Utils.parseMultipart(buffer, boundary).map (doc) =>
_meta = new Meta(meta.bucket, meta.key)
_meta.loadResponse { headers: doc.headers, statusCode: meta.statusCode }
_meta.vclock = meta.vclock
{ meta: _meta, data: @decodeBuffer(doc.body, _meta) }
{ meta: _meta, data: @decodeBuffer(doc.body, _meta, verb) }

cbFired = true

Expand All @@ -254,9 +254,11 @@ class HttpClient extends Client

# http client utils

decodeBuffer: (buffer, meta) ->
decodeBuffer: (buffer, meta, verb) ->
try
if buffer.length > 0 then meta.decode(buffer) else undefined
if meta.statusCode is 204 or verb is 'HEAD' then undefined
else if buffer == "" then buffer
else meta.decode(buffer)
catch e
new Error "Cannot convert response into #{meta.contentType}: #{e.message} -- Response: #{buffer}"

Expand Down

0 comments on commit 512b3ea

Please sign in to comment.