Class: Ferrum::Network::AuthRequest

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_idObject

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_idObject

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_typeObject

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

#abortObject

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.

Parameters:

  • source (String, Symbol)

    One of :server or :proxy.

Returns:

  • (Boolean)


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.

Parameters:

  • options (Hash)

Options Hash (**options):

  • :response (String)

    One of "Default", "CancelAuth", or "ProvideCredentials".

  • :username (String)
  • :password (String)


74
75
76
77
# File 'lib/ferrum/network/auth_request.rb', line 74

def continue(**options)
  options = options.merge(requestId: request_id)
  @page.command("Fetch.continueWithAuth", **options)
end

#headersHash{String => String}

The request headers.

Returns:

  • (Hash{String => String})


109
110
111
# File 'lib/ferrum/network/auth_request.rb', line 109

def headers
  @request["headers"]
end

#initial_priorityString

The request's initial priority, one of "VeryLow", "Low", "Medium", "High", or "VeryHigh".

Returns:

  • (String)


119
120
121
# File 'lib/ferrum/network/auth_request.rb', line 119

def initial_priority
  @request["initialPriority"]
end

#inspectString

Inspects the auth request.

Returns:

  • (String)


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.

Parameters:

  • pattern (String, Regexp)

Returns:

  • (Boolean)


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

#methodString

The request method.

Returns:

  • (String)


100
101
102
# File 'lib/ferrum/network/auth_request.rb', line 100

def method
  @request["method"]
end

Whether this request is for the navigation of a frame, as opposed to a subresource (script, image, XHR, etc).

Returns:

  • (Boolean)


28
29
30
# File 'lib/ferrum/network/auth_request.rb', line 28

def navigation_request?
  @params["isNavigationRequest"]
end

#referrer_policyString

The request's referrer policy.

Returns:

  • (String)


128
129
130
# File 'lib/ferrum/network/auth_request.rb', line 128

def referrer_policy
  @request["referrerPolicy"]
end

#urlString

The URL for the request.

Returns:

  • (String)


91
92
93
# File 'lib/ferrum/network/auth_request.rb', line 91

def url
  @request["url"]
end