lib/ably/rest/middleware/parse_message_pack.rb in ably-0.1.5 vs lib/ably/rest/middleware/parse_message_pack.rb in ably-0.1.6
- old
+ new
@@ -5,16 +5,20 @@
module Rest
module Middleware
class ParseMessagePack < Faraday::Response::Middleware
def on_complete(env)
if env.response_headers['Content-Type'] == 'application/x-msgpack'
- env.body = parse(env.body)
+ env.body = parse(env.body) unless env.response_headers['Ably-Middleware-Parsed'] == true
env.response_headers['Ably-Middleware-Parsed'] = true
end
end
def parse(body)
- MessagePack.unpack(body)
+ if body.length > 0
+ MessagePack.unpack(body)
+ else
+ body
+ end
rescue MessagePack::MalformedFormatError => e
raise Ably::Exceptions::InvalidResponseBody, "Expected MessagePack response: #{e.message}"
end
end
end