Class: Puppeteer::Response
- Inherits:
-
Object
- Object
- Puppeteer::Response
- Includes:
- IfPresent
- Defined in:
- lib/puppeteer/response.rb
Defined Under Namespace
Classes: InternalAccessor, Redirected, RemoteAddress, SecurityDetails
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#internal ⇒ Object
readonly
Returns the value of attribute internal.
-
#remote_address ⇒ Object
readonly
Returns the value of attribute remote_address.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#security_details ⇒ Object
readonly
Returns the value of attribute security_details.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_text ⇒ Object
readonly
Returns the value of attribute status_text.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #buffer ⇒ Object
- #frame ⇒ Object
- #from_cache? ⇒ Boolean
- #from_service_worker? ⇒ Boolean
-
#initialize(client, request, response_payload) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #ok? ⇒ Boolean
- #text ⇒ Object
Methods included from IfPresent
Constructor Details
#initialize(client, request, response_payload) ⇒ Response
Returns a new instance of Response.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/puppeteer/response.rb', line 34 def initialize(client, request, response_payload) @client = client @request = request @body_loaded_promise = resolvable_future @remote_address = RemoteAddress.new( ip: response_payload['remoteIPAddress'], port: response_payload['remotePort'], ) @status = response_payload['status'] @status_text = response_payload['statusText'] @url = request.url @from_disk_cache = !!response_payload['fromDiskCache'] @from_service_worker = !!response_payload['fromServiceWorker'] @headers = {} response_payload['headers'].each do |key, value| @headers[key.downcase] = value end @security_details = if_present(response_payload['securityDetails']) do |security_payload| SecurityDetails.new(security_payload) end @internal = InternalAccessor.new(self) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def headers @headers end |
#internal ⇒ Object (readonly)
Returns the value of attribute internal.
61 62 63 |
# File 'lib/puppeteer/response.rb', line 61 def internal @internal end |
#remote_address ⇒ Object (readonly)
Returns the value of attribute remote_address.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def remote_address @remote_address end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def request @request end |
#security_details ⇒ Object (readonly)
Returns the value of attribute security_details.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def security_details @security_details end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def status @status end |
#status_text ⇒ Object (readonly)
Returns the value of attribute status_text.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def status_text @status_text end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
63 64 65 |
# File 'lib/puppeteer/response.rb', line 63 def url @url end |
Instance Method Details
#buffer ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/puppeteer/response.rb', line 70 def buffer await @body_loaded_promise response = @client.('Network.getResponseBody', requestId: @request.internal.request_id) if response['base64Encoded'] Base64.decode64(response['body']) else response['body'] end end |
#frame ⇒ Object
98 99 100 |
# File 'lib/puppeteer/response.rb', line 98 def frame @request.frame end |
#from_cache? ⇒ Boolean
90 91 92 |
# File 'lib/puppeteer/response.rb', line 90 def from_cache? @from_disk_cache || @request.internal.from_memory_cache? end |
#from_service_worker? ⇒ Boolean
94 95 96 |
# File 'lib/puppeteer/response.rb', line 94 def from_service_worker? @from_service_worker end |
#json ⇒ Object
86 87 88 |
# File 'lib/puppeteer/response.rb', line 86 def json JSON.parse(text) end |
#ok? ⇒ Boolean
66 67 68 |
# File 'lib/puppeteer/response.rb', line 66 def ok? @status == 0 || (@status >= 200 && @status <= 299) end |
#text ⇒ Object
81 82 83 |
# File 'lib/puppeteer/response.rb', line 81 def text buffer end |