Class: Ferrum::Network::Response
- Inherits:
-
Object
- Object
- Ferrum::Network::Response
- Defined in:
- lib/ferrum/network/response.rb,
sig/ferrum/network/response.rbs
Overview
Represents a Network.Response object.
Instance Attribute Summary collapse
-
#body_size ⇒ Integer?
The response body size.
-
#loaded ⇒ Boolean
writeonly
private
The response is fully loaded by the browser.
-
#params ⇒ Hash{String => Object}
(also: #to_h)
readonly
The parsed JSON attributes for the Network.Response object.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the response's ID to another response's ID.
-
#body ⇒ String?
The response body.
-
#body! ⇒ String
The response body.
-
#content_type ⇒ String?
The
Content-Typeheader value of the response. -
#from_disk_cache? ⇒ Boolean
Whether the response was served from the browser's disk cache.
-
#from_service_worker? ⇒ Boolean
Whether a service worker answered the request instead of the network.
-
#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
Whether this response is the main frame's current response.
-
#redirect? ⇒ Boolean
Whether the response is a redirect.
-
#resource_type ⇒ String
The response's resource type, e.g.
-
#status ⇒ Integer
The HTTP status of the response.
-
#status_text ⇒ String
The HTTP status text.
-
#url ⇒ String
The URL of the response.
Constructor Details
#initialize(page, params) ⇒ Response
Initializes the responses object.
39 40 41 42 43 |
# File 'lib/ferrum/network/response.rb', line 39 def initialize(page, params) @page = page @params = params @response = params["response"] || params["redirectResponse"] end |
Instance Attribute Details
#body_size ⇒ Integer?
The writer is a private API, Ferrum sets it.
The response body size.
15 16 17 |
# File 'lib/ferrum/network/response.rb', line 15 def body_size @body_size end |
#loaded=(value) ⇒ Boolean (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The response is fully loaded by the browser.
28 29 30 |
# File 'lib/ferrum/network/response.rb', line 28 def loaded=(value) @loaded = value end |
#params ⇒ Hash{String => Object} (readonly) Also known as: to_h
The parsed JSON attributes for the Network.Response object.
21 22 23 |
# File 'lib/ferrum/network/response.rb', line 21 def params @params end |
Instance Method Details
#==(other) ⇒ Boolean
Compares the response's ID to another response's ID.
206 207 208 |
# File 'lib/ferrum/network/response.rb', line 206 def ==(other) id == other.id end |
#body ⇒ String?
The response body.
170 171 172 173 174 |
# File 'lib/ferrum/network/response.rb', line 170 def body body! rescue Ferrum::BrowserError # nop end |
#body! ⇒ String
The response body.
155 156 157 158 159 160 161 |
# File 'lib/ferrum/network/response.rb', line 155 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.
113 114 115 |
# File 'lib/ferrum/network/response.rb', line 113 def content_type @content_type ||= headers.find { |k, _| k.downcase == "content-type" }&.last&.sub(/;.*\z/, "") end |
#from_disk_cache? ⇒ Boolean
Whether the response was served from the browser's disk cache.
122 123 124 |
# File 'lib/ferrum/network/response.rb', line 122 def from_disk_cache? @response["fromDiskCache"] == true end |
#from_service_worker? ⇒ Boolean
Whether a service worker answered the request instead of the network.
131 132 133 |
# File 'lib/ferrum/network/response.rb', line 131 def from_service_worker? @response["fromServiceWorker"] == true end |
#headers ⇒ Hash{String => String}
The headers of the response.
86 87 88 |
# File 'lib/ferrum/network/response.rb', line 86 def headers @response["headers"] end |
#headers_size ⇒ Integer
The total size in bytes of the response.
95 96 97 |
# File 'lib/ferrum/network/response.rb', line 95 def headers_size @response["encodedDataLength"] end |
#id ⇒ String
The request ID associated with the response.
50 51 52 |
# File 'lib/ferrum/network/response.rb', line 50 def id @params["requestId"] end |
#inspect ⇒ String
Inspects the response object.
215 216 217 |
# File 'lib/ferrum/network/response.rb', line 215 def inspect %(#<#{self.class} @params=#{@params.inspect} @response=#{@response.inspect}>) end |
#loaded? ⇒ Boolean
The response is fully loaded by the browser or not.
188 189 190 |
# File 'lib/ferrum/network/response.rb', line 188 def loaded? @loaded end |
#main? ⇒ Boolean
Whether this response is the main frame's current response.
181 182 183 |
# File 'lib/ferrum/network/response.rb', line 181 def main? @page.network.response == self end |
#redirect? ⇒ Boolean
Whether the response is a redirect.
195 196 197 |
# File 'lib/ferrum/network/response.rb', line 195 def redirect? params.key?("redirectResponse") end |
#resource_type ⇒ String
The response's resource type, e.g. "Document", "Script" or "XHR".
104 105 106 |
# File 'lib/ferrum/network/response.rb', line 104 def resource_type @params["type"] end |
#status ⇒ Integer
The HTTP status of the response.
68 69 70 |
# File 'lib/ferrum/network/response.rb', line 68 def status @response["status"] end |
#status_text ⇒ String
The HTTP status text.
77 78 79 |
# File 'lib/ferrum/network/response.rb', line 77 def status_text @response["statusText"] end |
#url ⇒ String
The URL of the response.
59 60 61 |
# File 'lib/ferrum/network/response.rb', line 59 def url @response["url"] end |