Class: InfluxReporter::ErrorMessage::HTTP

Inherits:
Struct
  • Object
show all
Defined in:
lib/influx_reporter/error_message/http.rb

Constant Summary collapse

HTTP_ENV_KEY =
/^HTTP_/
UNDERSCORE =
'_'
DASH =
'-'
QUESTION =
'?'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies

Returns:

  • (Object)

    the current value of cookies



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def cookies
  @cookies
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def data
  @data
end

#envObject

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def env
  @env
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def headers
  @headers
end

#http_hostObject

Returns the value of attribute http_host

Returns:

  • (Object)

    the current value of http_host



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def http_host
  @http_host
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def method
  @method
end

#query_stringObject

Returns the value of attribute query_string

Returns:

  • (Object)

    the current value of query_string



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def query_string
  @query_string
end

#remote_hostObject

Returns the value of attribute remote_host

Returns:

  • (Object)

    the current value of remote_host



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def remote_host
  @remote_host
end

#secureObject

Returns the value of attribute secure

Returns:

  • (Object)

    the current value of secure



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def secure
  @secure
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent

Returns:

  • (Object)

    the current value of user_agent



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def user_agent
  @user_agent
end

#uuidObject

Returns the value of attribute uuid

Returns:

  • (Object)

    the current value of uuid



5
6
7
# File 'lib/influx_reporter/error_message/http.rb', line 5

def uuid
  @uuid
end

Class Method Details

.from_rack_env(env, opts = {}) ⇒ Object



15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/influx_reporter/error_message/http.rb', line 15

def self.from_rack_env(env, opts = {})
  req = if defined?(ActionDispatch::Request) && env.is_a?(ActionDispatch::Request)
          env
        else
          Rack::Request.new env
        end

  http = new(
      req.url.split(QUESTION).first,               # url
      req.request_method,                          # method
      nil,                                         # data
      req.query_string,                            # query string
      env['HTTP_COOKIE'],                          # cookies
      {},                                          # headers
      req.ip,                                      # remote host
      req.host_with_port,                          # http host
      req.user_agent,                              # user agent
      req.scheme == 'https', # secure
      {}, # env
      req.respond_to?(:uuid) ? req.uuid : nil
  )

  # In Rails < 5 ActionDispatch::Request inherits from Hash
  headers = env.respond_to?(:headers) ? env.headers : env

  headers.each do |k, v|
    next unless k.upcase == k # lower case stuff isn't relevant

    if k.match(HTTP_ENV_KEY)
      header = k.gsub(HTTP_ENV_KEY, '')
                   .split(UNDERSCORE).map(&:capitalize).join(DASH)
      http.headers[header] = v.to_s
    else
      http.env[k] = v.to_s
    end
  end

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

  if filter = opts[:filter]
    http.apply_filter filter
  end

  http
end

Instance Method Details

#apply_filter(filter) ⇒ Object



66
67
68
69
70
# File 'lib/influx_reporter/error_message/http.rb', line 66

def apply_filter(filter)
  self.data = filter.apply data
  self.query_string = filter.apply query_string
  self.cookies = filter.apply cookies
end