require "hashie"
require "faraday"
require "faraday_middleware"
require "multi_json"
require "uri"

module RabbitMQ
  module HTTP
    class ResponseHelper

      def initialize(client)
        @client = client
      end

      def decode_resource(response)
        if response.nil? || response.body.empty?
          Hashie::Mash.new
        else
          decode_response_body(response.body)
        end
      end

      def decode_response_body(body)
        if body.empty?
          Hashie::Mash.new
        else
          Hashie::Mash.new(body)
        end
      end

      def decode_resource_collection(response)
        collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')

        collection.map { |i| Hashie::Mash.new(i) }
      end
    end
  end
end

require "hashie"
require "faraday"
require "faraday_middleware"
require "multi_json"
require "uri"

module RabbitMQ
  module HTTP
    class ResponseHelper

      def initialize(client)
        @client = client
      end

      def decode_resource(response)
        if response.nil? || response.body.nil? || response.body.empty?
          Hashie::Mash.new
        else
          decode_response_body(response.body)
        end
      end

      def decode_response_body(body)
        if body.empty?
          Hashie::Mash.new
        else
          Hashie::Mash.new(body)
        end
      end

      def decode_resource_collection(response)
        collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')

        collection.map { |i| Hashie::Mash.new(i) }
      end
    end
  end
end

Handle 204 responses with HTTP keepalive
Handle 204 responses with HTTP keepalive

If the HTTP API is behind a proxy which has HTTP keepalive enabled, Faraday will assign a nil body on 204 responses.