Module: Radar::DataExtensions::RequestHelper

Included in:
Rack, Rails2
Defined in:
lib/radar/data_extensions/request_helper.rb

Overview

A mixin which contains helper methods for dealing with request objects.

Instance Method Summary collapse

Instance Method Details

#extract_http_headers(env) ⇒ Hash

Extracts only the HTTP headers from the rack environment, converting them to the proper HTTP format: HTTP_CONTENT_TYPE to Content-Type

Parameters:

  • env (Hash)

Returns:

  • (Hash)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/radar/data_extensions/request_helper.rb', line 12

def extract_http_headers(env)
  env.inject({}) do |acc, data|
    k, v = data

    if k =~ /^HTTP_(.+)$/
      # Convert things like HTTP_CONTENT_TYPE to Content-Type (standard
      # HTTP header style)
      k = $1.to_s.split("_").map { |c| c.capitalize }.join("-")
      acc[k] = v
    end

    acc
  end
end