Class: Ferrum::Network::AuthRequest
- Inherits:
-
Object
- Object
- Ferrum::Network::AuthRequest
- Defined in:
- lib/ferrum/network/auth_request.rb
Overview
Represents an HTTP authentication challenge (basic or digest auth
prompt) raised by the browser via Fetch.authRequired, which can be
answered with credentials or canceled.
Instance Attribute Summary collapse
-
#frame_id ⇒ Object
Returns the value of attribute frame_id.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
Instance Method Summary collapse
-
#abort ⇒ Object
Cancels the authentication challenge and the request.
-
#auth_challenge?(source) ⇒ Boolean
Whether the authentication challenge's source matches the given type.
-
#continue(**options) ⇒ Object
Responds to the authentication challenge, e.g.
-
#headers ⇒ Hash{String => String}
The request headers.
-
#initial_priority ⇒ String
The request's initial priority, one of
"VeryLow","Low","Medium","High", or"VeryHigh". -
#initialize(page, params) ⇒ AuthRequest
constructor
A new instance of AuthRequest.
-
#inspect ⇒ String
Inspects the auth request.
-
#match?(pattern) ⇒ Boolean
Whether the request's URL matches the given pattern.
-
#method ⇒ String
The request method.
-
#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.
-
#url ⇒ String
The URL for the request.
Constructor Details
#initialize(page, params) ⇒ AuthRequest
Returns a new instance of AuthRequest.
13 14 15 16 17 18 19 20 |
# File 'lib/ferrum/network/auth_request.rb', line 13 def initialize(page, params) @page = page @params = params @request_id = params["requestId"] @frame_id = params["frameId"] @resource_type = params["resourceType"] @request = params["request"] end |
Instance Attribute Details
#frame_id ⇒ Object
Returns the value of attribute frame_id.
11 12 13 |
# File 'lib/ferrum/network/auth_request.rb', line 11 def frame_id @frame_id end |
#request_id ⇒ Object
Returns the value of attribute request_id.
11 12 13 |
# File 'lib/ferrum/network/auth_request.rb', line 11 def request_id @request_id end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
11 12 13 |
# File 'lib/ferrum/network/auth_request.rb', line 11 def resource_type @resource_type end |
Instance Method Details
#abort ⇒ Object
Cancels the authentication challenge and the request.
82 83 84 |
# File 'lib/ferrum/network/auth_request.rb', line 82 def abort @page.command("Fetch.failRequest", requestId: request_id, errorReason: "BlockedByClient") end |
#auth_challenge?(source) ⇒ Boolean
Whether the authentication challenge's source matches the given type.
41 42 43 |
# File 'lib/ferrum/network/auth_request.rb', line 41 def auth_challenge?(source) @params.dig("authChallenge", "source")&.downcase&.to_s == source.to_s end |
#continue(**options) ⇒ Object
Responds to the authentication challenge, e.g. with credentials or by canceling it.
74 75 76 77 |
# File 'lib/ferrum/network/auth_request.rb', line 74 def continue(**) = .merge(requestId: request_id) @page.command("Fetch.continueWithAuth", **) end |
#headers ⇒ Hash{String => String}
The request headers.
109 110 111 |
# File 'lib/ferrum/network/auth_request.rb', line 109 def headers @request["headers"] end |
#initial_priority ⇒ String
The request's initial priority, one of "VeryLow", "Low",
"Medium", "High", or "VeryHigh".
119 120 121 |
# File 'lib/ferrum/network/auth_request.rb', line 119 def initial_priority @request["initialPriority"] end |
#inspect ⇒ String
Inspects the auth request.
137 138 139 140 141 142 143 |
# File 'lib/ferrum/network/auth_request.rb', line 137 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.
52 53 54 55 56 57 58 59 |
# File 'lib/ferrum/network/auth_request.rb', line 52 def match?(pattern) case url when pattern true else false end end |
#method ⇒ String
The request method.
100 101 102 |
# File 'lib/ferrum/network/auth_request.rb', line 100 def method @request["method"] end |
#navigation_request? ⇒ Boolean
Whether this request is for the navigation of a frame, as opposed to a subresource (script, image, XHR, etc).
28 29 30 |
# File 'lib/ferrum/network/auth_request.rb', line 28 def @params["isNavigationRequest"] end |
#referrer_policy ⇒ String
The request's referrer policy.
128 129 130 |
# File 'lib/ferrum/network/auth_request.rb', line 128 def referrer_policy @request["referrerPolicy"] end |
#url ⇒ String
The URL for the request.
91 92 93 |
# File 'lib/ferrum/network/auth_request.rb', line 91 def url @request["url"] end |