module VCR::Normalizers::Body

def self.included(klass)

def self.included(klass)
  klass.extend ClassMethods
end

def base_body_hash(body)

def base_body_hash(body)
  { 'encoding' => body.encoding.name }
end

def base_body_hash(body)

def base_body_hash(body)
  { }
end

def initialize(*args)

def initialize(*args)
  super
  if body && !body.is_a?(String)
    raise ArgumentError, "#{self.class} initialized with an invalid (non-String) body of class #{body.class}: #{body.inspect}."
  end
  # Ensure that the body is a raw string, in case the string instance
  # has been subclassed or extended with additional instance variables
  # or attributes, so that it is serialized to YAML as a raw string.
  # This is needed for rest-client.  See this ticket for more info:
  # http://github.com/myronmarston/vcr/issues/4
  self.body = String.new(body.to_s)
end

def serializable_body

def serializable_body
  # Ensure it's just a string, and not a string with some
  # extra state, as such strings serialize to YAML with
  # all the extra state.
  body = String.new(self.body.to_s)
  if VCR.configuration.preserve_exact_body_bytes_for?(self)
    base_body_hash(body).merge('base64_string' => Base64.encode64(body))
  else
    base_body_hash(body).merge('string' => body)
  end
end