ruby-amqp / rabbitmq_http_api_client

RabbitMQ HTTP API client for Ruby
MIT License
79 stars 49 forks source link

Empty object returned when "content-length" header is null, even if content is present #48

Closed rquant closed 3 years ago

rquant commented 3 years ago

Hi. I came across an issue in which when requesting exchange info against our CloudAMQP host. The response body contains the correct data, but the "content-length" header is null. This causes an empty Hashie Mash object to get returned due to the following code:

def decode_resource(response)
        case response.headers["content-length"]
        when nil then Hashie::Mash.new
        when 0   then Hashie::Mash.new
        when "0" then Hashie::Mash.new
        else
          if response.body.empty?
            Hashie::Mash.new
          else
            Hashie::Mash.new(response.body)
          end
        end
      end

Here is a screenshot of my debugging context to demonstrate the issue:

Screen Shot 2021-01-07 at 5 01 28 AM