Class: Typhoeus::Response
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#app_time ⇒ Float
Approximated time the web application took to process the request.
- #content_type ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(*args) ⇒ Response
constructor
A new instance of Response.
- #location ⇒ Object
- #old_initialize ⇒ Object
- #redirection? ⇒ Boolean
- #text? ⇒ Boolean
-
#to_hash ⇒ Hash
Converts self to hash.
Constructor Details
#initialize(*args) ⇒ Response
Returns a new instance of Response.
23 24 25 26 |
# File 'lib/arachni/typhoeus/response.rb', line 23 def initialize( *args ) old_initialize( *args ) @body = @body.recode if text? end |
Instance Method Details
#[](k) ⇒ Object
28 29 30 |
# File 'lib/arachni/typhoeus/response.rb', line 28 def []( k ) find_header_value( k ) end |
#[]=(k, v) ⇒ Object
32 33 34 |
# File 'lib/arachni/typhoeus/response.rb', line 32 def []=( k, v ) headers_hash[find_header_field( k ) || k] = v end |
#app_time ⇒ Float
Returns Approximated time the web application took to process the request.
70 71 72 |
# File 'lib/arachni/typhoeus/response.rb', line 70 def app_time timed_out? ? time : start_transfer_time - pretransfer_time end |
#content_type ⇒ Object
55 56 57 58 |
# File 'lib/arachni/typhoeus/response.rb', line 55 def content_type ct = find_header_value( 'content-type' ) ct.is_a?( Array ) ? ct.last : ct end |
#each(&block) ⇒ Object
36 37 38 |
# File 'lib/arachni/typhoeus/response.rb', line 36 def each( &block ) headers_hash.each( &block ) end |
#location ⇒ Object
60 61 62 |
# File 'lib/arachni/typhoeus/response.rb', line 60 def location find_header_value( 'location' ) end |
#old_initialize ⇒ Object
22 |
# File 'lib/arachni/typhoeus/response.rb', line 22 alias :old_initialize :initialize |
#redirection? ⇒ Boolean
64 65 66 |
# File 'lib/arachni/typhoeus/response.rb', line 64 def redirection? (300..399).include?( @code ) || !location.nil? end |
#text? ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/arachni/typhoeus/response.rb', line 40 def text? return if !@body if (type = content_type) return true if type.start_with?( 'text/' ) # Non "application/" content types will surely not be text-based # so bail out early. return false if !type.start_with?( 'application/' ) end # Last resort, more resource intensive binary detection. !@body.binary? end |
#to_hash ⇒ Hash
Returns converts self to hash.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/arachni/typhoeus/response.rb', line 75 def to_hash hash = {} instance_variables.each do |var| hash[var.to_s.gsub( /@/, '' )] = instance_variable_get( var ) end hash['headers_hash'] = {} headers_hash.to_hash.each_pair { |k, v| hash['headers_hash'][k] = v } hash.delete( 'request' ) hash end |