pub struct RouteHandlerRegistry { /* private fields */ }Expand description
Route handler registry for a page or context.
Implementations§
Source§impl RouteHandlerRegistry
impl RouteHandlerRegistry
Sourcepub fn new(connection: Arc<CdpConnection>, session_id: String) -> Self
pub fn new(connection: Arc<CdpConnection>, session_id: String) -> Self
Create a new route handler registry.
Sourcepub fn with_credentials(
connection: Arc<CdpConnection>,
session_id: String,
credentials: HttpCredentials,
) -> Self
pub fn with_credentials( connection: Arc<CdpConnection>, session_id: String, credentials: HttpCredentials, ) -> Self
Create a new route handler registry with HTTP credentials.
Sourcepub fn with_context_routes(
connection: Arc<CdpConnection>,
session_id: String,
context_routes: Arc<ContextRouteRegistry>,
http_credentials: Option<HttpCredentials>,
) -> Self
pub fn with_context_routes( connection: Arc<CdpConnection>, session_id: String, context_routes: Arc<ContextRouteRegistry>, http_credentials: Option<HttpCredentials>, ) -> Self
Create a new route handler registry with context-level routes.
If http_credentials is provided, they will be set on the auth handler
for handling HTTP authentication challenges.
Sourcepub async fn enable_fetch_for_context_routes(&self) -> Result<(), NetworkError>
pub async fn enable_fetch_for_context_routes(&self) -> Result<(), NetworkError>
Enable Fetch domain if context has routes or auth is enabled.
This should be called after the registry is created to check if there are context-level routes that need interception or if HTTP credentials are configured.
Sourcepub fn set_context_routes(&mut self, context_routes: Arc<ContextRouteRegistry>)
pub fn set_context_routes(&mut self, context_routes: Arc<ContextRouteRegistry>)
Set the context-level route registry.
Sourcepub fn start_fetch_listener(self: &Arc<Self>)
pub fn start_fetch_listener(self: &Arc<Self>)
Start the background fetch event listener.
This spawns a background task that listens for Fetch.requestPaused and
Fetch.authRequired events and dispatches them to the appropriate handlers.
Also listens for context route change notifications to enable Fetch when new routes are added to the context after the page was created.
This should be called after creating the registry, passing an Arc reference to self.
Sourcepub async fn set_http_credentials(&self, credentials: HttpCredentials)
pub async fn set_http_credentials(&self, credentials: HttpCredentials)
Set HTTP credentials for authentication.
Sourcepub async fn clear_http_credentials(&self)
pub async fn clear_http_credentials(&self)
Clear HTTP credentials.
Sourcepub async fn handle_auth_required(
&self,
event: &AuthRequiredEvent,
) -> Result<(), NetworkError>
pub async fn handle_auth_required( &self, event: &AuthRequiredEvent, ) -> Result<(), NetworkError>
Handle an authentication challenge.
Sourcepub async fn route<M, H, Fut>(
&self,
pattern: M,
handler: H,
) -> Result<(), NetworkError>
pub async fn route<M, H, Fut>( &self, pattern: M, handler: H, ) -> Result<(), NetworkError>
Register a route handler for the given pattern.
Sourcepub async fn route_predicate<P, H, Fut>(
&self,
predicate: P,
handler: H,
) -> Result<(), NetworkError>
pub async fn route_predicate<P, H, Fut>( &self, predicate: P, handler: H, ) -> Result<(), NetworkError>
Register a route handler with a predicate function.
Sourcepub async fn unroute_all(&self)
pub async fn unroute_all(&self)
Unregister all handlers.
Sourcepub async fn handle_request(
&self,
event: &RequestPausedEvent,
) -> Result<(), NetworkError>
pub async fn handle_request( &self, event: &RequestPausedEvent, ) -> Result<(), NetworkError>
Handle a paused request by dispatching to matching handlers.
Handlers are tried in reverse order (LIFO). If a handler calls fallback(),
the next matching handler is tried. If no handler handles the request,
it is continued to the network.
Sourcepub async fn ensure_fetch_enabled_public(&self) -> Result<(), NetworkError>
pub async fn ensure_fetch_enabled_public(&self) -> Result<(), NetworkError>
Enable the Fetch domain if not already enabled.
This is a public version for use by ContextRouteRegistry when
synchronously enabling Fetch on all pages after a context route is added.