Class: TingYun::Agent::Transaction::RequestAttributes
- Inherits:
-
Object
- Object
- TingYun::Agent::Transaction::RequestAttributes
- Defined in:
- lib/ting_yun/agent/transaction/request_attributes.rb
Constant Summary collapse
- HTTP_ACCEPT_HEADER_KEY =
'HTTP_ACCEPT'.freeze
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#queryString ⇒ Object
readonly
Returns the value of attribute queryString.
-
#referer ⇒ Object
readonly
Returns the value of attribute referer.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #assign_agent_attributes(attributes) ⇒ Object
- #assign_request_attributes(attributes) ⇒ Object
- #assign_user_info_attributes(attributes) ⇒ Object
-
#initialize(request) ⇒ RequestAttributes
constructor
A new instance of RequestAttributes.
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 = (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
#accept ⇒ Object (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_length ⇒ Object (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 |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
11 12 13 |
# File 'lib/ting_yun/agent/transaction/request_attributes.rb', line 11 def @cookie end |
#header ⇒ Object (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 |
#host ⇒ Object (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 |
#ip ⇒ Object (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 |
#params ⇒ Object (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 |
#port ⇒ Object (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 |
#queryString ⇒ Object (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 |
#referer ⇒ Object (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_method ⇒ Object (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_path ⇒ Object (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 |
#url ⇒ Object (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_agent ⇒ Object (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 assign_user_info_attributes(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.add_user_info("origin"=> 1) attributes.add_user_info("value"=> @params[r["value"]]) elsif [7,10].include?(r["type"]) && !@cookie.nil? attributes.add_user_info("origin"=> 1) attributes.add_user_info("value"=> @cookie[r["value"]]) end end end |