Class: Html2rss::RequestService::PuppetCommander::NavigationGuards
- Inherits:
-
Object
- Object
- Html2rss::RequestService::PuppetCommander::NavigationGuards
- Defined in:
- lib/html2rss/request_service/puppet_commander/navigation_guards.rb
Overview
Owns Puppeteer request interception, deferred navigation errors, main-frame filtering, and redirect-chain validation via Html2rss::RequestService::Policy.
Does not re-own Policy rules — only calls validate_*! on ctx.policy.
Instance Attribute Summary collapse
-
#latest_navigation_response ⇒ Puppeteer::HTTPResponse?
readonly
Latest main-frame navigation response.
Class Method Summary collapse
-
.response_url(navigation_response, fallback_url) ⇒ Html2rss::Url
Resolves the final response URL for Response building and IP validation.
Instance Method Summary collapse
-
#begin_navigation! ⇒ void
Clears deferred error and latest navigation response before goto.
-
#initialize(ctx:, skip_request_resources:) ⇒ NavigationGuards
constructor
A new instance of NavigationGuards.
-
#install!(page) ⇒ void
Captures the main frame and wires request/response interceptors.
-
#raise_deferred_error! ⇒ void
Re-raises a deferred navigation error when one was captured.
-
#validate_final!(navigation_response) ⇒ void
Validates the remote IP of a navigation response via Policy.
Constructor Details
#initialize(ctx:, skip_request_resources:) ⇒ NavigationGuards
Returns a new instance of NavigationGuards.
28 29 30 31 32 33 34 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 28 def initialize(ctx:, skip_request_resources:) @ctx = ctx @skip_request_resources = skip_request_resources @navigation_error = nil @latest_navigation_response = nil @main_frame = nil end |
Instance Attribute Details
#latest_navigation_response ⇒ Puppeteer::HTTPResponse? (readonly)
Returns latest main-frame navigation response.
68 69 70 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 68 def @latest_navigation_response end |
Class Method Details
.response_url(navigation_response, fallback_url) ⇒ Html2rss::Url
Resolves the final response URL for Response building and IP validation.
19 20 21 22 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 19 def response_url(, fallback_url) raw_url = &.url || fallback_url.to_s Html2rss::Url.from_absolute(raw_url) end |
Instance Method Details
#begin_navigation! ⇒ void
This method returns an undefined value.
Clears deferred error and latest navigation response before goto.
52 53 54 55 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 52 def @navigation_error = nil @latest_navigation_response = nil end |
#install!(page) ⇒ void
This method returns an undefined value.
Captures the main frame and wires request/response interceptors.
41 42 43 44 45 46 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 41 def install!(page) @main_frame = page.main_frame if page.respond_to?(:main_frame) page.request_interception = true page.on('request') { |request| handle_request(request) } page.on('response') { |response| handle_response(response) } end |
#raise_deferred_error! ⇒ void
This method returns an undefined value.
Re-raises a deferred navigation error when one was captured.
62 63 64 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 62 def raise_deferred_error! raise @navigation_error if @navigation_error end |
#validate_final!(navigation_response) ⇒ void
This method returns an undefined value.
Validates the remote IP of a navigation response via Policy.
75 76 77 78 |
# File 'lib/html2rss/request_service/puppet_commander/navigation_guards.rb', line 75 def validate_final!() final_url = self.class.response_url(, ctx.url) ctx.policy.validate_remote_ip!(ip: remote_ip(), url: final_url) end |