Class: Ferrum::Network::InterceptedRequest
- Inherits:
-
Object
- Object
- Ferrum::Network::InterceptedRequest
- Includes:
- RequestParams
- Defined in:
- lib/ferrum/network/intercepted_request.rb
Overview
Represents a request paused by request interception (Fetch.enable),
allowing it to be continued as is or with overrides, fulfilled with a
fake response, or aborted before it reaches the network.
Instance Attribute Summary collapse
-
#frame_id ⇒ Object
Returns the value of attribute frame_id.
-
#network_id ⇒ Object
Returns the value of attribute network_id.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#abort ⇒ Object
Aborts the intercepted request.
-
#continue(**options) ⇒ Object
Continues the intercepted request, letting it reach the network as is, or with the given overrides.
-
#initial_priority ⇒ String
The request's initial priority, one of
"VeryLow","Low","Medium","High", or"VeryHigh". -
#initialize(client, params) ⇒ InterceptedRequest
constructor
A new instance of InterceptedRequest.
-
#inspect ⇒ String
Inspects the intercepted request.
-
#match?(pattern) ⇒ Boolean
Whether the request's URL matches the given pattern.
-
#navigation_request? ⇒ Boolean
Whether this request is for the navigation of a frame, as opposed to a subresource (script, image, XHR, etc).
-
#referrer_policy ⇒ String
The request's referrer policy.
-
#respond(**options) ⇒ Object
Fulfills the intercepted request with a fake response instead of letting it reach the network.
-
#status?(value) ⇒ Boolean
Whether the request's current status matches the given value.
Methods included from RequestParams
#headers, #method, #post_data, #url, #url_fragment
Constructor Details
#initialize(client, params) ⇒ InterceptedRequest
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ferrum/network/intercepted_request.rb', line 18 def initialize(client, params) @status = nil @client = client @params = params @request_id = params["requestId"] @frame_id = params["frameId"] @resource_type = params["resourceType"] @request = params["request"] @network_id = params["networkId"] end |
Instance Attribute Details
#frame_id ⇒ Object
Returns the value of attribute frame_id.
16 17 18 |
# File 'lib/ferrum/network/intercepted_request.rb', line 16 def frame_id @frame_id end |
#network_id ⇒ Object
Returns the value of attribute network_id.
16 17 18 |
# File 'lib/ferrum/network/intercepted_request.rb', line 16 def network_id @network_id end |
#request_id ⇒ Object
Returns the value of attribute request_id.
16 17 18 |
# File 'lib/ferrum/network/intercepted_request.rb', line 16 def request_id @request_id end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
16 17 18 |
# File 'lib/ferrum/network/intercepted_request.rb', line 16 def resource_type @resource_type end |
#status ⇒ Object
Returns the value of attribute status.
16 17 18 |
# File 'lib/ferrum/network/intercepted_request.rb', line 16 def status @status end |
Instance Method Details
#abort ⇒ Object
Aborts the intercepted request.
131 132 133 134 |
# File 'lib/ferrum/network/intercepted_request.rb', line 131 def abort @status = :aborted @client.command("Fetch.failRequest", async: true, requestId: request_id, errorReason: "BlockedByClient") end |
#continue(**options) ⇒ Object
Continues the intercepted request, letting it reach the network as is, or with the given overrides.
119 120 121 122 123 |
# File 'lib/ferrum/network/intercepted_request.rb', line 119 def continue(**) = .merge(requestId: request_id) @status = :continued @client.command("Fetch.continueRequest", async: true, **) end |
#initial_priority ⇒ String
The request's initial priority, one of "VeryLow", "Low",
"Medium", "High", or "VeryHigh".
142 143 144 |
# File 'lib/ferrum/network/intercepted_request.rb', line 142 def initial_priority @request["initialPriority"] end |
#inspect ⇒ String
Inspects the intercepted request.
160 161 162 163 164 165 166 |
# File 'lib/ferrum/network/intercepted_request.rb', line 160 def inspect "#<#{self.class} " \ "@request_id=#{@request_id.inspect} " \ "@frame_id=#{@frame_id.inspect} " \ "@resource_type=#{@resource_type.inspect} " \ "@request=#{@request.inspect}>" end |
#match?(pattern) ⇒ Boolean
Whether the request's URL matches the given pattern.
58 59 60 61 62 63 64 65 |
# File 'lib/ferrum/network/intercepted_request.rb', line 58 def match?(pattern) case url when pattern true else false end end |
#navigation_request? ⇒ Boolean
Whether this request is for the navigation of a frame, as opposed to a subresource (script, image, XHR, etc).
47 48 49 |
# File 'lib/ferrum/network/intercepted_request.rb', line 47 def @params["isNavigationRequest"] end |
#referrer_policy ⇒ String
The request's referrer policy.
151 152 153 |
# File 'lib/ferrum/network/intercepted_request.rb', line 151 def referrer_policy @request["referrerPolicy"] end |
#respond(**options) ⇒ Object
Fulfills the intercepted request with a fake response instead of letting it reach the network.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ferrum/network/intercepted_request.rb', line 85 def respond(**) has_body = .key?(:body) headers = has_body ? { "content-length" => .fetch(:body, "").length } : {} headers = headers.merge(.fetch(:responseHeaders, {})) = { responseCode: 200 }.merge() = .merge(requestId: request_id, responseHeaders: header_array(headers)) = .merge(body: Base64.strict_encode64(.fetch(:body, ""))) if has_body @status = :responded @client.command("Fetch.fulfillRequest", async: true, **) end |
#status?(value) ⇒ Boolean
Whether the request's current status matches the given value.
37 38 39 |
# File 'lib/ferrum/network/intercepted_request.rb', line 37 def status?(value) @status == value.to_sym end |