class InfluxReporter::ErrorMessage::HTTP
Constants
- DASH
- HTTP_ENV_KEY
- QUESTION
- UNDERSCORE
Public Class Methods
from_rack_env(env, opts = {})
click to toggle source
# 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
Public Instance Methods
apply_filter(filter)
click to toggle source
# 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