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-1.0.7 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-1.0.6 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.6 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-1.0.5 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.5 lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.4 lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.3 lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.2 lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.1 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-1.0.0 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-1.0.0 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.8.15 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-0.8.15 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.9.3 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.9.2 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.9.1 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.9.0 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.8.14 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb
ably-0.8.14 lib/ably/rest/middleware/parse_message_pack.rb
ably-rest-0.8.13 lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb