Class: Ferrum::Network::AuthRequest

Inherits:
Object
  • Object
show all
Includes:
RequestParams
Defined in:
lib/ferrum/network/auth_request.rb,
sig/ferrum/network/auth_request.rbs

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

Methods included from RequestParams

#body, #headers, #initial_priority, #match?, #method, #referrer_policy, #url, #url_fragment

Constructor Details

#initialize(page, params) ⇒ AuthRequest

Returns a new instance of AuthRequest.

Parameters:

  • page (Page)
  • params (Hash[::String, untyped])


28
29
30
31
32
33
34
35
36
# File 'lib/ferrum/network/auth_request.rb', line 28

def initialize(page, params)
  @page = page
  @params = params
  @id = params["requestId"]
  @frame_id = params["frameId"]
  @resource_type = params["resourceType"]
  @request = params["request"]
  @handled = false
end

Instance Attribute Details

#frame_id ⇒ ::String

Note:

The writer is a private API, Ferrum sets it.

Returns:

  • (::String)


23
24
25
# File 'lib/ferrum/network/auth_request.rb', line 23

def frame_id
  @frame_id
end

#id ⇒ String

Note:

The writer is a private API, Ferrum sets it.

The id of the paused request, the requestId that Fetch commands take.

Returns:

  • (String)


20
21
22
# File 'lib/ferrum/network/auth_request.rb', line 20

def id
  @id
end

#resource_type ⇒ "Document", ...

Note:

The writer is a private API, Ferrum sets it.

Returns:

  • ("Document", "Stylesheet", "Image", "Media", "Font", "Script", "TextTrack", "XHR", "Fetch", "Prefetch")


23
24
25
# File 'lib/ferrum/network/auth_request.rb', line 23

def resource_type
  @resource_type
end

Instance Method Details

#abort ⇒ Object

Cancels the authentication challenge, so the request completes with the unauthorized response.

Returns:

  • (Object)


93
94
95
# File 'lib/ferrum/network/auth_request.rb', line 93

def abort
  continue(authChallengeResponse: { response: "CancelAuth" })
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)


66
67
68
# File 'lib/ferrum/network/auth_request.rb', line 66

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)
  • response: ("Default", "CancelAuth", "ProvideCredentials")
  • username: (::String)
  • password: (::String)

Options Hash (**options):

  • :response (String) —

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

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

Returns:

  • (Object)


83
84
85
86
87
# File 'lib/ferrum/network/auth_request.rb', line 83

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

#handled? ⇒ Boolean

Whether the challenge was answered or canceled.

Returns:

  • (Boolean)


43
44
45
# File 'lib/ferrum/network/auth_request.rb', line 43

def handled?
  @handled
end

#inspect ⇒ String

Inspects the auth request.

Returns:

  • (String)


102
103
104
105
106
107
108
# File 'lib/ferrum/network/auth_request.rb', line 102

def inspect
  "#<#{self.class} " \
    "@id=#{@id.inspect} " \
    "@frame_id=#{@frame_id.inspect} " \
    "@resource_type=#{@resource_type.inspect} " \
    "@request=#{@request.inspect}>"
end

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

Returns:

  • (Boolean)


53
54
55
# File 'lib/ferrum/network/auth_request.rb', line 53

def navigation_request?
  resource_type == "Document"
end