Class: WebkitRemote::Client::NetworkResource

Inherits:
Object
  • Object
show all
Defined in:
lib/webkit_remote/client/network_events.rb

Overview

Wraps information about the network operations for retrieving a resource.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_id, client) ⇒ NetworkResource

Creates an empty network operation wrapper.

Parameters:

  • remote_id (String)

    the request_id used by the remote debugging server to identify this network operation

  • (WebkitRemote::Client)


265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/webkit_remote/client/network_events.rb', line 265

def initialize(remote_id, client)
  @remote_id = remote_id
  @client = client
  @request = nil
  @response = nil
  @type = nil
  @document_url = nil
  @initiator = nil
  @canceled = false
  @last_event = nil
  @body = false
end

Instance Attribute Details

#canceledBoolean (readonly)

Returns true if the request fetch was canceled.

Returns:

  • (Boolean)

    true if the request fetch was canceled



243
244
245
# File 'lib/webkit_remote/client/network_events.rb', line 243

def canceled
  @canceled
end

#clientWebkitRemote::Client (readonly)

Returns remote debugging client that reported this.

Returns:



253
254
255
# File 'lib/webkit_remote/client/network_events.rb', line 253

def client
  @client
end

#document_urlString (readonly)

Returns the URL of the document that referenced this resource.

Returns:

  • (String)

    the URL of the document that referenced this resource



236
237
238
# File 'lib/webkit_remote/client/network_events.rb', line 236

def document_url
  @document_url
end

#errorString (readonly)

Returns error message, if the resource fetching failed.

Returns:

  • (String)

    error message, if the resource fetching failed



246
247
248
# File 'lib/webkit_remote/client/network_events.rb', line 246

def error
  @error
end

#initiatorWebkitRemote::Client::NetworkRequestInitiator (readonly)

Returns cause for this resource to be fetched from the network.

Returns:



240
241
242
# File 'lib/webkit_remote/client/network_events.rb', line 240

def initiator
  @initiator
end

#last_eventWebkitRemote::Event (readonly)

Returns last event connected to this resource; can be used to determine the resource’s status.

Returns:

  • (WebkitRemote::Event)

    last event connected to this resource; can be used to determine the resource’s status



250
251
252
# File 'lib/webkit_remote/client/network_events.rb', line 250

def last_event
  @last_event
end

#remote_idString (readonly)

Returns request_id assigned by the remote WebKit debugger.

Returns:

  • (String)

    request_id assigned by the remote WebKit debugger



256
257
258
# File 'lib/webkit_remote/client/network_events.rb', line 256

def remote_id
  @remote_id
end

#requestWebkitRemote::Client::NetworkRequest (readonly)

Returns network request (most likely HTTP) used to fetch this resource.

Returns:



224
225
226
# File 'lib/webkit_remote/client/network_events.rb', line 224

def request
  @request
end

#responseWebkitRemote::Client::NetworkRequest (readonly)

Returns network response that contains this resource.

Returns:



228
229
230
# File 'lib/webkit_remote/client/network_events.rb', line 228

def response
  @response
end

#typeSymbol (readonly)

Returns the type of this resource; documented values are :document, :font, :image, :other, :script, :stylesheet, :websocket and :xhr.

Returns:

  • (Symbol)

    the type of this resource; documented values are :document, :font, :image, :other, :script, :stylesheet, :websocket and :xhr



233
234
235
# File 'lib/webkit_remote/client/network_events.rb', line 233

def type
  @type
end

Instance Method Details

#add_event(event) ⇒ Object



338
339
340
341
# File 'lib/webkit_remote/client/network_events.rb', line 338

def add_event(event)
  @last_event = event
  # TODO(pwnall): consider keeping track of all events
end

#bodyString

Returns the contents of the resource.

Returns:

  • (String)

    the contents of the resource



279
280
281
# File 'lib/webkit_remote/client/network_events.rb', line 279

def body
  @body ||= body!
end

#body!String

Re-fetches the resource from the Webkit remote debugging server.

Returns:

  • (String)

    the contents of the resource



286
287
288
289
290
291
292
293
# File 'lib/webkit_remote/client/network_events.rb', line 286

def body!
  result = @client.rpc.call 'Network.getResponseBody', requestId: @remote_id
  if result['base64Encoded']
    @body = Base64.decode64 result['body']
  else
    @body = result['body']
  end
end

#set_canceled(new_canceled) ⇒ Object



296
297
298
# File 'lib/webkit_remote/client/network_events.rb', line 296

def set_canceled(new_canceled)
  @canceled ||= new_canceled
end

#set_document_url(new_document_url) ⇒ Object



301
302
303
304
# File 'lib/webkit_remote/client/network_events.rb', line 301

def set_document_url(new_document_url)
  return if new_document_url == nil
  @document_url = new_document_url
end

#set_error(new_error) ⇒ Object



307
308
309
310
# File 'lib/webkit_remote/client/network_events.rb', line 307

def set_error(new_error)
  return if new_error == nil
  @error = new_error
end

#set_initiator(new_initiator) ⇒ Object



313
314
315
316
# File 'lib/webkit_remote/client/network_events.rb', line 313

def set_initiator(new_initiator)
  return if new_initiator == nil
  @initiator = new_initiator
end

#set_request(new_request) ⇒ Object



319
320
321
322
323
# File 'lib/webkit_remote/client/network_events.rb', line 319

def set_request(new_request)
  return if new_request == nil
  # TODO(pwnall): consider handling multiple requests
  @request = new_request
end

#set_response(new_response) ⇒ Object



326
327
328
329
# File 'lib/webkit_remote/client/network_events.rb', line 326

def set_response(new_response)
  return if new_response == nil
  @response = new_response
end

#set_type(new_type) ⇒ Object



332
333
334
335
# File 'lib/webkit_remote/client/network_events.rb', line 332

def set_type(new_type)
  return if new_type == nil
  @type = new_type
end