Class: Arachni::HTTP::Response
- Defined in:
- lib/arachni/http/response.rb,
lib/arachni/http/response/scope.rb
Overview
HTTP Response representation.
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#app_time ⇒ Float
Approximate time the web application took to process the #request.
-
#code ⇒ Integer
HTTP response status code.
-
#headers_string ⇒ String
Raw headers.
-
#ip_address ⇒ String
IP address of the server.
-
#message ⇒ String
HTTP response status message.
-
#redirections ⇒ Array<Response>
Automatically followed redirections that eventually led to this response.
- #request ⇒ Request
-
#return_code ⇒ Symbol
‘libcurl` return code.
-
#return_message ⇒ String
‘libcurl` return code.
-
#time ⇒ Float
Time, in seconds, it took from the start until the full response was received.
-
#total_time ⇒ Float
Total time in seconds for the transfer, including name resolving, TCP connect etc.
Attributes inherited from Message
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #body=(body) ⇒ Object
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Response
constructor
A new instance of Response.
-
#modified? ⇒ Boolean
‘true` if the remote resource has been modified since the date given in the `If-Modified-Since` request header field, `false` otherwise.
-
#platforms ⇒ Platform
Applicable platforms for the page.
-
#redirect? ⇒ Boolean
(also: #redirection?)
‘true` if the response is a `3xx` redirect and there is a `Location` header field.
-
#status_line ⇒ String
First line of the response.
-
#text? ⇒ Bool
‘true` if the response body is textual in nature, `false` if binary, `nil` if could not be determined.
-
#timed_out? ⇒ Boolean
‘true` if timed out, `false` otherwise.
- #to_h ⇒ Hash
- #to_page ⇒ Arachni::Page
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
-
#to_s ⇒ String
HTTP response string.
Methods inherited from Message
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arachni/http/response.rb', line 64 def initialize( = {} ) super( ) @body ||= '' @code ||= 0 # Holds the redirection responses that eventually led to this one. @redirections ||= [] @time ||= 0.0 end |
Instance Attribute Details
#app_time ⇒ Float
Returns Approximate time the web application took to process the #request.
62 63 64 |
# File 'lib/arachni/http/response.rb', line 62 def app_time @app_time end |
#code ⇒ Integer
Returns HTTP response status code.
20 21 22 |
# File 'lib/arachni/http/response.rb', line 20 def code @code end |
#headers_string ⇒ String
Returns Raw headers.
48 49 50 |
# File 'lib/arachni/http/response.rb', line 48 def headers_string @headers_string end |
#ip_address ⇒ String
Returns IP address of the server.
24 25 26 |
# File 'lib/arachni/http/response.rb', line 24 def ip_address @ip_address end |
#message ⇒ String
Returns HTTP response status message.
28 29 30 |
# File 'lib/arachni/http/response.rb', line 28 def @message end |
#redirections ⇒ Array<Response>
Returns Automatically followed redirections that eventually led to this response.
36 37 38 |
# File 'lib/arachni/http/response.rb', line 36 def redirections @redirections end |
#request ⇒ Request
Returns HTTP Arachni::HTTP::Request which triggered this Arachni::HTTP::Response.
32 33 34 |
# File 'lib/arachni/http/response.rb', line 32 def request @request end |
#return_code ⇒ Symbol
Returns ‘libcurl` return code.
40 41 42 |
# File 'lib/arachni/http/response.rb', line 40 def return_code @return_code end |
#return_message ⇒ String
Returns ‘libcurl` return code.
44 45 46 |
# File 'lib/arachni/http/response.rb', line 44 def @return_message end |
#time ⇒ Float
Returns Time, in seconds, it took from the start until the full response was received.
58 59 60 |
# File 'lib/arachni/http/response.rb', line 58 def time @time end |
#total_time ⇒ Float
Returns Total time in seconds for the transfer, including name resolving, TCP connect etc.
53 54 55 |
# File 'lib/arachni/http/response.rb', line 53 def total_time @total_time end |
Class Method Details
.from_rpc_data(data) ⇒ Request
190 191 192 193 194 |
# File 'lib/arachni/http/response.rb', line 190 def self.from_rpc_data( data ) data['request'] = Request.from_rpc_data( data['request'] ) data['return_code'] = data['return_code'].to_sym if data['return_code'] new data end |
.from_typhoeus(response) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/arachni/http/response.rb', line 204 def self.from_typhoeus( response ) redirections = response.redirections.map do |redirect| rurl = URI.to_absolute( redirect.headers['Location'], response.effective_url ) rurl ||= response.effective_url # Broken redirection, skip it... next if !rurl new( url: rurl, code: redirect.code, headers: redirect.headers ) end new( url: response.effective_url, code: response.code, ip_address: response.primary_ip, headers: response.headers, headers_string: response.response_headers, body: response.body, redirections: redirections, time: response.time, app_time: (response.timed_out? ? response.time : response.start_transfer_time - response.pretransfer_time).to_f, total_time: response.total_time.to_f, return_code: response.return_code, return_message: response. ) end |
Instance Method Details
#==(other) ⇒ Object
196 197 198 |
# File 'lib/arachni/http/response.rb', line 196 def ==( other ) hash == other.hash end |
#body=(body) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/arachni/http/response.rb', line 148 def body=( body ) @body = body.to_s.dup text_check = text? @body.recode! if text_check.nil? || text_check @body.freeze end |
#hash ⇒ Object
200 201 202 |
# File 'lib/arachni/http/response.rb', line 200 def hash to_h.hash end |
#modified? ⇒ Boolean
Depends on the response code.
Returns ‘true` if the remote resource has been modified since the date given in the `If-Modified-Since` request header field, `false` otherwise.
116 117 118 |
# File 'lib/arachni/http/response.rb', line 116 def modified? code != 304 end |
#platforms ⇒ Platform
Returns Applicable platforms for the page.
82 83 84 |
# File 'lib/arachni/http/response.rb', line 82 def platforms Platform::Manager[url] end |
#redirect? ⇒ Boolean Also known as: redirection?
Returns ‘true` if the response is a `3xx` redirect and there is a `Location` header field.
102 103 104 |
# File 'lib/arachni/http/response.rb', line 102 def redirect? code >= 300 && code <= 399 && !!headers.location end |
#status_line ⇒ String
Returns First line of the response.
88 89 90 91 |
# File 'lib/arachni/http/response.rb', line 88 def status_line return if !headers_string @status_line ||= headers_string.lines.first.to_s.chomp.freeze end |
#text? ⇒ Bool
Returns ‘true` if the response body is textual in nature, `false` if binary, `nil` if could not be determined.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/arachni/http/response.rb', line 123 def text? return if !@body if (type = headers.content_type) return true if type.start_with?( 'text/' ) # Non "text/" nor "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. begin !@body.binary? rescue ArgumentError nil end end |
#timed_out? ⇒ Boolean
Returns ‘true` if timed out, `false` otherwise.
144 145 146 |
# File 'lib/arachni/http/response.rb', line 144 def timed_out? [:operation_timedout, :couldnt_connect].include? return_code end |
#to_h ⇒ Hash
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/arachni/http/response.rb', line 163 def to_h hash = {} instance_variables.each do |var| hash[var.to_s.gsub( /@/, '' ).to_sym] = instance_variable_get( var ) end hash[:headers] = {}.merge( hash[:headers] ) hash.delete( :scope ) hash.delete( :parsed_url ) hash.delete( :redirections ) hash.delete( :request ) hash.delete( :scope ) hash end |
#to_page ⇒ Arachni::Page
158 159 160 |
# File 'lib/arachni/http/response.rb', line 158 def to_page Page.from_response self end |
#to_rpc_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
182 183 184 185 186 |
# File 'lib/arachni/http/response.rb', line 182 def to_rpc_data data = to_h data[:request] = request.to_rpc_data data.my_stringify_keys(false) end |
#to_s ⇒ String
Returns HTTP response string.
95 96 97 |
# File 'lib/arachni/http/response.rb', line 95 def to_s "#{headers_string}#{body}" end |