Method: M2R::Headers#rackify

Defined in:
lib/m2r/headers.rb

#rackify(env = {}) ⇒ Hash

Fill Hash with Headers compatibile with Rack standard. Every header except for Content-Length and Content-Type is capitalized, underscored, and prefixed with HTTP. Content-Length and Content-Type are not prefixed (according to the spec)

Parameters:

  • env (Hash) (defaults to: {})

    Hash representing Rack Env or compatible

Returns:

  • (Hash)

    same Hash as provided as argument.



60
61
62
63
64
65
66
67
68
# File 'lib/m2r/headers.rb', line 60

def rackify(env = {})
  @headers.each do |header, value|
    key = "HTTP_" + header.upcase.gsub("-", "_")
    env[key] = value
  end
  env["CONTENT_LENGTH"] = env.delete("HTTP_CONTENT_LENGTH") if env.key?("HTTP_CONTENT_LENGTH")
  env["CONTENT_TYPE"]   = env.delete("HTTP_CONTENT_TYPE")   if env.key?("HTTP_CONTENT_TYPE")
  env
end