Class: Raven::HttpInterface

Inherits:
Interface show all
Defined in:
lib/raven/interfaces/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Interface

name

Methods included from BetterAttrAccessor

#attributes, included

Constructor Details

#initialize(*arguments) ⇒ HttpInterface

Returns a new instance of HttpInterface.



15
16
17
18
19
# File 'lib/raven/interfaces/http.rb', line 15

def initialize(*arguments)
  self.headers = {}
  self.env = {}
  super(*arguments)
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



11
12
13
# File 'lib/raven/interfaces/http.rb', line 11

def cookies
  @cookies
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/raven/interfaces/http.rb', line 9

def data
  @data
end

#envObject

Returns the value of attribute env.



13
14
15
# File 'lib/raven/interfaces/http.rb', line 13

def env
  @env
end

#headersObject

Returns the value of attribute headers.



12
13
14
# File 'lib/raven/interfaces/http.rb', line 12

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/raven/interfaces/http.rb', line 8

def method
  @method
end

#query_stringObject

Returns the value of attribute query_string.



10
11
12
# File 'lib/raven/interfaces/http.rb', line 10

def query_string
  @query_string
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/raven/interfaces/http.rb', line 7

def url
  @url
end

Instance Method Details

#from_rack(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/raven/interfaces/http.rb', line 21

def from_rack(env)
  require 'rack'
  req = ::Rack::Request.new(env)
  self.url = req.url.split('?').first
  self.method = req.request_method
  self.query_string = req.query_string
  env.each_pair do |key, value|
    next unless key.upcase == key # Non-upper case stuff isn't either
    if key.start_with?('HTTP_')
      # Header
      http_key = key[5..key.length - 1].split('_').map { |s| s.capitalize }.join('-')
      self.headers[http_key] = value.to_s
    elsif ['CONTENT_TYPE', 'CONTENT_LENGTH'].include? key
      self.headers[key.capitalize] = value.to_s
    elsif ['REMOTE_ADDR', 'SERVER_NAME', 'SERVER_PORT'].include? key
      # Environment
      self.env[key] = value.to_s
    end
  end

  self.data =
    if req.form_data?
      req.POST
    elsif req.body
      data = req.body.read
      req.body.rewind
      data
    end
end