Class: HttpLog::HttpRequest

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/http_log/http_request.rb

Instance Method Summary collapse

Instance Method Details

#acceptsObject



3
4
5
# File 'lib/http_log/http_request.rb', line 3

def accepts
  Array.wrap(super).map(&:to_s)
end

#header_hashObject



7
8
9
10
11
12
13
14
# File 'lib/http_log/http_request.rb', line 7

def header_hash
  header_keys = env.keys.select {|k| k =~ /HTTP_\w+/ }
  hash = {}
  header_keys.each do |key|
    hash[key] = env[key]
  end
  hash
end

#paramsObject



26
27
28
29
30
31
32
33
34
# File 'lib/http_log/http_request.rb', line 26

def params
  if content_type =~ /json/ && raw_post.present?
    super.merge(MultiJson.decode(raw_post) || {})
  elsif content_type =~ /xml/ && raw_post.present?
    super.merge(Hash.from_xml(raw_post) || {})
  else
    super
  end
end

#raw_postObject



20
21
22
23
24
# File 'lib/http_log/http_request.rb', line 20

def raw_post
  result = body.read
  body.rewind
  result
end