Class: TingYun::Agent::Transaction::RequestAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/ting_yun/agent/transaction/request_attributes.rb

Constant Summary collapse

HTTP_ACCEPT_HEADER_KEY =
'HTTP_ACCEPT'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestAttributes

Returns a new instance of RequestAttributes.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 16

def initialize request
  @header = request.env
  @request_path = path_from_request request
  @referer = referer_from_request request
  @accept = attribute_from_env request, HTTP_ACCEPT_HEADER_KEY
  @content_length = content_length_from_request request
  @host = attribute_from_request request, :host
  @port = port_from_request request
  @user_agent = attribute_from_request request, :user_agent
  @request_method = attribute_from_request request, :request_method
  @cookie = set_cookie(request)
  @ip = attribute_from_env(request, 'HTTP_X_FORWARDED_FOR')|| request.ip
  @url = request.scheme + "://"+ request.host_with_port +  @request_path
  @params =  request.params
  @queryString = request.query_string
end

Instance Attribute Details

#acceptObject (readonly)

Returns the value of attribute accept.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def accept
  @accept
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def content_length
  @content_length
end

Returns the value of attribute cookie.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def cookie
  @cookie
end

#headerObject (readonly)

Returns the value of attribute header.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def header
  @header
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def host
  @host
end

#ipObject (readonly)

Returns the value of attribute ip.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def ip
  @ip
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def params
  @params
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def port
  @port
end

#queryStringObject (readonly)

Returns the value of attribute queryString.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def queryString
  @queryString
end

#refererObject (readonly)

Returns the value of attribute referer.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def referer
  @referer
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def request_method
  @request_method
end

#request_pathObject (readonly)

Returns the value of attribute request_path.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def request_path
  @request_path
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def url
  @url
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



11
12
13
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11

def user_agent
  @user_agent
end

Instance Method Details

#assign_agent_attributes(attributes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 33

def assign_agent_attributes(attributes)
  attributes.add_agent_attribute :request_path, request_path
  attributes.add_agent_attribute :referer, referer  unless referer.nil?
  attributes.add_agent_attribute :accept, accept
  attributes.add_agent_attribute :contentLength, content_length  unless content_length.nil?
  attributes.add_agent_attribute :host, host
  attributes.add_agent_attribute :port, port
  attributes.add_agent_attribute :userAgent, user_agent
  attributes.add_agent_attribute :method, request_method
  attributes.add_agent_attribute :ip, ip
  attributes.add_agent_attribute :url, url
  attributes.add_agent_attribute :queryString, queryString
  attributes.response_header.merge! attributes.agent_attributes
  attributes.add_agent_attribute :params, params
  attributes.add_agent_attribute :cookie, @cookie
end

#assign_request_attributes(attributes) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 63

def assign_request_attributes(attributes)
  attributes.add_request_params :request_path, request_path
  attributes.add_request_params :referer, referer unless referer.nil?
  attributes.add_request_params :accept, accept
  attributes.add_request_params(:contentLength, content_length) unless content_length.nil?
  attributes.add_request_params :host, host
  attributes.add_request_params :port, port
  attributes.add_request_params :userAgent, user_agent
  attributes.add_request_params :method, request_method
  attributes.add_request_params :ip, ip
  attributes.add_request_params :url, url
  attributes.add_request_params :params, params
  attributes.add_request_params :queryString, queryString
end

#assign_user_info_attributes(attributes) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 50

def (attributes)
  rule = TingYun::Support::Serialize::JSONWrapper.load(TingYun::Agent.config[:'user_info.rules'])
  rule["list"].each do |r|
    if [2,9].include?(r["type"]) && !@params.nil?
      attributes.("origin"=> 1)
      attributes.("value"=> @params[r["value"]])
    elsif [7,10].include?(r["type"]) && !@cookie.nil?
      attributes.("origin"=> 1)
      attributes.("value"=> @cookie[r["value"]])
    end
  end
end