Class: Ferrum::Network::Response
- Inherits:
-
Object
- Object
- Ferrum::Network::Response
- Defined in:
- lib/ferrum/network/response.rb
Overview
Represents a [Network.Response](chromedevtools.github.io/devtools-protocol/1-3/Network/#type-Response) object.
Instance Attribute Summary collapse
-
#body_size ⇒ Integer?
The response body size.
-
#loaded ⇒ Boolean
writeonly
The response is fully loaded by the browser.
-
#params ⇒ Hash{String => Object}
(also: #to_h)
readonly
The parsed JSON attributes for the [Network.Response](chromedevtools.github.io/devtools-protocol/1-3/Network/#type-Response) object.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the response’s ID to another response’s ID.
-
#body ⇒ String
The response body.
-
#content_type ⇒ String?
The ‘Content-Type` header value of the response.
-
#headers ⇒ Hash{String => String}
The headers of the response.
-
#headers_size ⇒ Integer
The total size in bytes of the response.
-
#id ⇒ String
The request ID associated with the response.
-
#initialize(page, params) ⇒ Response
constructor
Initializes the responses object.
-
#inspect ⇒ String
Inspects the response object.
-
#loaded? ⇒ Boolean
The response is fully loaded by the browser or not.
- #main? ⇒ Boolean
-
#redirect? ⇒ Boolean
Whether the response is a redirect.
-
#status ⇒ Integer
The HTTP status of the response.
-
#status_text ⇒ String
The HTTP status text.
-
#type ⇒ String
The resource type of the response.
-
#url ⇒ String
The URL of the response.
Constructor Details
#initialize(page, params) ⇒ Response
Initializes the responses object.
35 36 37 38 39 |
# File 'lib/ferrum/network/response.rb', line 35 def initialize(page, params) @page = page @params = params @response = params["response"] || params["redirectResponse"] end |
Instance Attribute Details
#body_size ⇒ Integer?
The response body size.
13 14 15 |
# File 'lib/ferrum/network/response.rb', line 13 def body_size @body_size end |
#loaded=(value) ⇒ Boolean (writeonly)
The response is fully loaded by the browser.
24 25 26 |
# File 'lib/ferrum/network/response.rb', line 24 def loaded=(value) @loaded = value end |
#params ⇒ Hash{String => Object} (readonly) Also known as: to_h
The parsed JSON attributes for the [Network.Response](chromedevtools.github.io/devtools-protocol/1-3/Network/#type-Response) object.
19 20 21 |
# File 'lib/ferrum/network/response.rb', line 19 def params @params end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the response’s ID to another response’s ID.
163 164 165 |
# File 'lib/ferrum/network/response.rb', line 163 def ==(other) id == other.id end |
#body ⇒ String
The response body.
127 128 129 130 131 132 133 |
# File 'lib/ferrum/network/response.rb', line 127 def body @body ||= begin body, encoded = @page.command("Network.getResponseBody", requestId: id) .values_at("body", "base64Encoded") encoded ? Base64.decode64(body) : body end end |
#content_type ⇒ String?
The ‘Content-Type` header value of the response.
109 110 111 |
# File 'lib/ferrum/network/response.rb', line 109 def content_type @content_type ||= headers.find { |k, _| k.downcase == "content-type" }&.last&.sub(/;.*\z/, "") end |
#headers ⇒ Hash{String => String}
The headers of the response.
82 83 84 |
# File 'lib/ferrum/network/response.rb', line 82 def headers @response["headers"] end |
#headers_size ⇒ Integer
The total size in bytes of the response.
91 92 93 |
# File 'lib/ferrum/network/response.rb', line 91 def headers_size @response["encodedDataLength"] end |
#id ⇒ String
The request ID associated with the response.
46 47 48 |
# File 'lib/ferrum/network/response.rb', line 46 def id @params["requestId"] end |
#inspect ⇒ String
Inspects the response object.
172 173 174 |
# File 'lib/ferrum/network/response.rb', line 172 def inspect %(#<#{self.class} @params=#{@params.inspect} @response=#{@response.inspect}>) end |
#loaded? ⇒ Boolean
The response is fully loaded by the browser or not.
145 146 147 |
# File 'lib/ferrum/network/response.rb', line 145 def loaded? @loaded end |
#main? ⇒ Boolean
138 139 140 |
# File 'lib/ferrum/network/response.rb', line 138 def main? @page.network.response == self end |
#redirect? ⇒ Boolean
Whether the response is a redirect.
152 153 154 |
# File 'lib/ferrum/network/response.rb', line 152 def redirect? params.key?("redirectResponse") end |
#status ⇒ Integer
The HTTP status of the response.
64 65 66 |
# File 'lib/ferrum/network/response.rb', line 64 def status @response["status"] end |
#status_text ⇒ String
The HTTP status text.
73 74 75 |
# File 'lib/ferrum/network/response.rb', line 73 def status_text @response["statusText"] end |
#type ⇒ String
The resource type of the response.
100 101 102 |
# File 'lib/ferrum/network/response.rb', line 100 def type @params["type"] end |
#url ⇒ String
The URL of the response.
55 56 57 |
# File 'lib/ferrum/network/response.rb', line 55 def url @response["url"] end |