Class: HttpMessage
- Inherits:
-
Object
- Object
- HttpMessage
- Defined in:
- lib/resurfaceio/http_message.rb
Direct Known Subclasses
Class Method Summary collapse
- .append_request_headers(message, request) ⇒ Object
- .append_request_params(message, request) ⇒ Object
- .append_response_headers(message, response) ⇒ Object
- .append_value(message, key, value = nil) ⇒ Object
- .build(request, response, response_body = nil, request_body = nil) ⇒ Object
- .send(logger, request, response, response_body = nil, request_body = nil, now = nil, interval = nil) ⇒ Object
Class Method Details
.append_request_headers(message, request) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/resurfaceio/http_message.rb', line 45 def self.append_request_headers(, request) respond_to_env = request.respond_to?(:env) if respond_to_env || request.respond_to?(:headers) headers = respond_to_env ? request.env : request.headers headers.each do |name, value| unless value.nil? if name =~ /^CONTENT_TYPE/ << ['request_header:content-type', value] end if name =~ /^HTTP_/ << ["request_header:#{name[5..-1].downcase.tr('_', '-')}", value] end end end unless headers.nil? end end |
.append_request_params(message, request) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/resurfaceio/http_message.rb', line 62 def self.append_request_params(, request) respond_to_env = request.respond_to?(:env) if respond_to_env || request.respond_to?(:form_hash) hash = respond_to_env ? request.env['rack.request.form_hash'] : request.form_hash hash.each do |name, value| append_value , "request_param:#{name.downcase}", value end unless hash.nil? end if respond_to_env || request.respond_to?(:query_hash) hash = respond_to_env ? request.env['rack.request.query_hash'] : request.query_hash hash.each do |name, value| append_value , "request_param:#{name.downcase}", value end unless hash.nil? end end |
.append_response_headers(message, response) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/resurfaceio/http_message.rb', line 78 def self.append_response_headers(, response) found_content_type = false if response.respond_to?(:headers) response.headers.each do |name, value| unless value.nil? name = name.downcase found_content_type = true if name =~ /^content-type/ << ["response_header:#{name}", value] end end unless response.headers.nil? end unless found_content_type || response.content_type.nil? << ['response_header:content-type', response.content_type] end end |
.append_value(message, key, value = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/resurfaceio/http_message.rb', line 94 def self.append_value(, key, value = nil) unless key.nil? unless value.nil? case value when Array << [key, value.join] when String << [key, value] else << [key, value.to_s] end end end end |
.build(request, response, response_body = nil, request_body = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/resurfaceio/http_message.rb', line 31 def self.build(request, response, response_body = nil, request_body = nil) = [] append_value , 'request_method', request.request_method unless request.request_method.nil? append_value , 'request_url', request.url unless request.url.nil? append_value , 'response_code', response.status unless response.status.nil? append_request_headers , request append_request_params , request append_response_headers , response append_value , 'request_body', request_body unless request_body == '' final_response_body = response_body.nil? ? response.body : response_body append_value , 'response_body', final_response_body unless final_response_body == '' return end |
.send(logger, request, response, response_body = nil, request_body = nil, now = nil, interval = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/resurfaceio/http_message.rb', line 8 def self.send(logger, request, response, response_body = nil, request_body = nil, now = nil, interval = nil) return unless logger.enabled? # copy details from request & response = build(request, response, response_body, request_body) # copy details from active session unless logger.rules.copy_session_field.empty? ssn = request.session if !ssn.nil? && ssn.respond_to?(:keys) logger.rules.copy_session_field.each do |r| ssn.keys.each {|d| ( << ["session_field:#{d}", ssn[d].to_s]) if r.param1.match(d)} end end end # add timing details << ['now', now.nil? ? (Time.now.to_f * 1000).floor.to_s : now] << ['interval', interval] unless interval.nil? logger.submit_if_passing() end |