Sha256: d03a7a698a8bdc3e1d85b32c0f66b52834889f00fa820353993265d434c876ea

Contents?: true

Size: 777 Bytes

Versions: 51

Compression:

Stored size: 777 Bytes

Contents

require 'faraday'
require 'msgpack'

module Ably
  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) unless env.response_headers['Ably-Middleware-Parsed'] == true
            env.response_headers['Ably-Middleware-Parsed'] = true
          end
        end

        def parse(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
  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
ably-0.7.6 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.7.5 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-0.7.5 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.7.4 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.7.3 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-0.7.2 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.7.1 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.7.0 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.6.2 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.2.0 lib/ably/rest/middleware/parse_message_pack.rb
ably-0.1.6 lib/ably/rest/middleware/parse_message_pack.rb