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 |
# 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 ||= [] 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
184 185 186 187 188 |
# File 'lib/arachni/http/response.rb', line 184 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
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/arachni/http/response.rb', line 198 def self.from_typhoeus( response ) redirections = response.redirections.map do |redirect| new( url: redirect.headers['Location'] || response.effective_url, 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, total_time: response.total_time, return_code: response.return_code, return_message: response. ) end |
Instance Method Details
#==(other) ⇒ Object
190 191 192 |
# File 'lib/arachni/http/response.rb', line 190 def ==( other ) hash == other.hash end |
#body=(body) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/arachni/http/response.rb', line 142 def body=( body ) @body = body.to_s.dup text_check = text? @body.recode! if text_check.nil? || text_check @body.freeze end |
#hash ⇒ Object
194 195 196 |
# File 'lib/arachni/http/response.rb', line 194 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.
110 111 112 |
# File 'lib/arachni/http/response.rb', line 110 def modified? code != 304 end |
#platforms ⇒ Platform
Returns Applicable platforms for the page.
76 77 78 |
# File 'lib/arachni/http/response.rb', line 76 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.
96 97 98 |
# File 'lib/arachni/http/response.rb', line 96 def redirect? code >= 300 && code <= 399 && !!headers.location end |
#status_line ⇒ String
Returns First line of the response.
82 83 84 85 |
# File 'lib/arachni/http/response.rb', line 82 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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/arachni/http/response.rb', line 117 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.
138 139 140 |
# File 'lib/arachni/http/response.rb', line 138 def timed_out? [:operation_timedout, :couldnt_connect].include? return_code end |
#to_h ⇒ Hash
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/arachni/http/response.rb', line 157 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
152 153 154 |
# File 'lib/arachni/http/response.rb', line 152 def to_page Page.from_response self end |
#to_rpc_data ⇒ Hash
Returns Data representing this instance that are suitable the RPC transmission.
176 177 178 179 180 |
# File 'lib/arachni/http/response.rb', line 176 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.
89 90 91 |
# File 'lib/arachni/http/response.rb', line 89 def to_s "#{headers_string}#{body}" end |