class Ferrum::Network::InterceptedRequest

Attributes

frame_id[RW]
network_id[RW]
request_id[RW]
resource_type[RW]
status[RW]

Public Class Methods

new(page, params) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 10
def initialize(page, params)
  @status = nil
  @page, @params = page, params
  @request_id = params["requestId"]
  @frame_id = params["frameId"]
  @resource_type = params["resourceType"]
  @request = params["request"]
  @network_id = params["networkId"]
end

Public Instance Methods

abort() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 54
def abort
  @status = :aborted
  @page.command("Fetch.failRequest", requestId: request_id, errorReason: "BlockedByClient")
end
continue(**options) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 48
def continue(**options)
  options = options.merge(requestId: request_id)
  @status = :continued
  @page.command("Fetch.continueRequest", **options)
end
headers() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 67
def headers
  @request["headers"]
end
initial_priority() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 71
def initial_priority
  @request["initialPriority"]
end
inspect() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 79
def inspect
  %(#<#{self.class} @request_id=#{@request_id.inspect} @frame_id=#{@frame_id.inspect} @resource_type=#{@resource_type.inspect} @request=#{@request.inspect}>)
end
match?(regexp) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 28
def match?(regexp)
  !!url.match(regexp)
end
method() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 63
def method
  @request["method"]
end
navigation_request?() click to toggle source
referrer_policy() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 75
def referrer_policy
  @request["referrerPolicy"]
end
respond(**options) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 32
def respond(**options)
  has_body = options.has_key?(:body)
  headers = has_body ? { "content-length" => options.fetch(:body, "").length } : {}
  headers = headers.merge(options.fetch(:responseHeaders, {}))

  options = {responseCode: 200}.merge(options)
  options = options.merge({
    requestId: request_id,
    responseHeaders: header_array(headers),
  })
  options = options.merge(body: Base64.strict_encode64(options.fetch(:body, ""))) if has_body

  @status = :responded
  @page.command("Fetch.fulfillRequest", **options)
end
status?(value) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 20
def status?(value)
  @status == value.to_sym
end
url() click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 59
def url
  @request["url"]
end

Private Instance Methods

header_array(values) click to toggle source
# File lib/ferrum/network/intercepted_request.rb, line 85
def header_array(values)
  values.map do |key, value|
    { name: String(key), value: String(value) }
  end
end