lib/jsonapionify/api/server/request.rb in jsonapionify-0.0.1.pre vs lib/jsonapionify/api/server/request.rb in jsonapionify-0.9.0

- old
+ new

@@ -8,17 +8,17 @@ options[:method] = method new Rack::MockRequest.env_for(url, options) end def headers - Rack::Utils::HeaderHash.new( - env.select do |name, _| - name.start_with?('HTTP_') && !%w{HTTP_VERSION}.include?(name) - end.each_with_object({}) do |(name, value), hash| - hash[name[5..-1].gsub('_', '-')] = value - end - ) + env_headers = env.select do |name, _| + name.start_with?('HTTP_') && !%w{HTTP_VERSION}.include?(name) + end.each_with_object({}) do |(name, value), hash| + hash[name[5..-1].gsub('_', '-').downcase] = value + end + env_headers['content-type'] = content_type + Rack::Utils::HeaderHash.new(env_headers) end def http_string # GET /path/file.html HTTP/1.0 # From: someuser@jmarshall.com @@ -40,9 +40,13 @@ JSON.pretty_generate(Oj.load(value)) rescue Oj::ParseError value ensure body.rewind + end + + def content_type + super.try(:split, ';').try(:first) end def accept accepts = (headers['accept'] || '*/*').split(',') accepts.to_a.sort_by! do |accept|