Class: Ferrum::Network::Exchange
- Inherits:
-
Object
- Object
- Ferrum::Network::Exchange
- Defined in:
- lib/ferrum/network/exchange.rb
Overview
Pairs a Request with its eventual Response or Error (and, if interception is enabled, its InterceptedRequest), representing the full lifecycle of a single network request.
Instance Attribute Summary collapse
-
#error ⇒ Error?
The error object.
-
#id ⇒ Object
readonly
ID of the request.
-
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
-
#request ⇒ Request?
The request object.
-
#request_extra_info ⇒ Hash?
private
The raw
Network.requestWillBeSentExtraInfoparams for the request, if it arrived beforerequestwas set. -
#response ⇒ Response?
The response object.
-
#unknown ⇒ Object
Determines if the network exchange is unknown due to a lost of its context.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Determines if the network exchange has a request.
-
#blob? ⇒ Boolean
Determines if the exchange is blob.
-
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
-
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred or the exchange is unknown and cannot be inferred.
-
#initialize(page, id) ⇒ Exchange
constructor
Initializes the network exchange.
-
#inspect ⇒ String
Inspects the network exchange.
-
#intercepted? ⇒ Boolean
Determines if the exchange's request was intercepted.
-
#loader_id ⇒ String?
The loader ID of the request.
-
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
-
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
-
#ping? ⇒ Boolean
Determines if the exchange is ping.
-
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
-
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
-
#url ⇒ String?
Returns request's URL.
-
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
Constructor Details
#initialize(page, id) ⇒ Exchange
Initializes the network exchange.
57 58 59 60 61 62 63 64 |
# File 'lib/ferrum/network/exchange.rb', line 57 def initialize(page, id) @id = id @page = page @intercepted_request = nil @request = @response = @error = nil @request_extra_info = nil @unknown = false end |
Instance Attribute Details
#error ⇒ Error?
The error object.
34 35 36 |
# File 'lib/ferrum/network/exchange.rb', line 34 def error @error end |
#id ⇒ Object (readonly)
ID of the request.
14 15 16 |
# File 'lib/ferrum/network/exchange.rb', line 14 def id @id end |
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
19 20 21 |
# File 'lib/ferrum/network/exchange.rb', line 19 def intercepted_request @intercepted_request end |
#request ⇒ Request?
The request object.
24 25 26 |
# File 'lib/ferrum/network/exchange.rb', line 24 def request @request end |
#request_extra_info ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The raw Network.requestWillBeSentExtraInfo params for the request,
if it arrived before request was set.
48 49 50 |
# File 'lib/ferrum/network/exchange.rb', line 48 def request_extra_info @request_extra_info end |
#response ⇒ Response?
The response object.
29 30 31 |
# File 'lib/ferrum/network/exchange.rb', line 29 def response @response end |
#unknown ⇒ Object
Determines if the network exchange is unknown due to a lost of its context
40 41 42 |
# File 'lib/ferrum/network/exchange.rb', line 40 def unknown @unknown end |
Instance Method Details
#blank? ⇒ Boolean
Determines if the network exchange has a request.
92 93 94 |
# File 'lib/ferrum/network/exchange.rb', line 92 def blank? !request end |
#blob? ⇒ Boolean
Determines if the exchange is blob.
165 166 167 |
# File 'lib/ferrum/network/exchange.rb', line 165 def blob? !!url&.start_with?("blob:") end |
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
101 102 103 |
# File 'lib/ferrum/network/exchange.rb', line 101 def blocked? intercepted? && intercepted_request.status?(:aborted) end |
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred or the exchange is unknown and cannot be inferred.
111 112 113 |
# File 'lib/ferrum/network/exchange.rb', line 111 def finished? blocked? || response&.loaded? || !error.nil? || ping? || blob? || unknown end |
#inspect ⇒ String
Inspects the network exchange.
192 193 194 195 196 197 198 199 200 |
# File 'lib/ferrum/network/exchange.rb', line 192 def inspect "#<#{self.class} " \ "@id=#{@id.inspect} " \ "@intercepted_request=#{@intercepted_request.inspect} " \ "@request=#{@request.inspect} " \ "@response=#{@response.inspect} " \ "@error=#{@error.inspect}> " \ "@unknown=#{@unknown.inspect}>" end |
#intercepted? ⇒ Boolean
Determines if the exchange's request was intercepted.
129 130 131 |
# File 'lib/ferrum/network/exchange.rb', line 129 def intercepted? !intercepted_request.nil? end |
#loader_id ⇒ String?
The loader ID of the request.
83 84 85 |
# File 'lib/ferrum/network/exchange.rb', line 83 def loader_id request&.loader_id end |
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
74 75 76 |
# File 'lib/ferrum/network/exchange.rb', line 74 def (frame_id) request&.type?(:document) && request&.frame_id == frame_id end |
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
120 121 122 |
# File 'lib/ferrum/network/exchange.rb', line 120 def pending? !finished? end |
#ping? ⇒ Boolean
Determines if the exchange is ping.
156 157 158 |
# File 'lib/ferrum/network/exchange.rb', line 156 def ping? !!request&.ping? end |
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
147 148 149 |
# File 'lib/ferrum/network/exchange.rb', line 147 def redirect? response&.redirect? end |
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
183 184 185 |
# File 'lib/ferrum/network/exchange.rb', line 183 def to_a [request, response, error] end |
#url ⇒ String?
Returns request's URL.
174 175 176 |
# File 'lib/ferrum/network/exchange.rb', line 174 def url request&.url end |
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
138 139 140 |
# File 'lib/ferrum/network/exchange.rb', line 138 def xhr? !!request&.xhr? end |