Class: Html2rss::RequestService::PuppetCommander
- Inherits:
-
Object
- Object
- Html2rss::RequestService::PuppetCommander
- Defined in:
- lib/html2rss/request_service/puppet_commander.rb,
lib/html2rss/request_service/puppet_commander/preload_runner.rb,
lib/html2rss/request_service/puppet_commander/navigation_guards.rb
Overview
Commands the Puppeteer Browser to the website and builds the Response.
Public interface is #call; page setup, navigation, and body collection are private orchestration steps.
Defined Under Namespace
Classes: NavigationGuards, PreloadRunner
Constant Summary collapse
- BROWSER_UNSAFE_HEADERS =
Request header names that must not be forwarded to the browser session.
%w[ host connection content-length transfer-encoding sec-fetch-dest sec-fetch-mode sec-fetch-site sec-fetch-user upgrade-insecure-requests ].to_set.freeze
Instance Method Summary collapse
-
#call ⇒ Response
Visits the request URL and normalizes the page into a response object.
-
#initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) ⇒ PuppetCommander
constructor
A new instance of PuppetCommander.
Constructor Details
#initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) ⇒ PuppetCommander
Returns a new instance of PuppetCommander.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 22 def initialize(ctx, browser, skip_request_resources: %w[stylesheet image media font].to_set, referer: [ctx.url.scheme, ctx.url.host].join('://')) @ctx = ctx @browser = browser @referer = referer @navigation_guards = NavigationGuards.new(ctx:, skip_request_resources:) @preload_runner = PreloadRunner.new(ctx:) end |
Instance Method Details
#call ⇒ Response
Visits the request URL and normalizes the page into a response object.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/html2rss/request_service/puppet_commander.rb', line 37 def call page = new_page = navigate_to_destination(page, ctx.url) preload_runner.call(page) .raise_deferred_error! = . || .validate_final!() build_response(page, ) ensure page&.close end |