pub struct Route { /* private fields */ }Expand description
An intercepted network request that can be fulfilled, continued, or aborted.
When a request matches a route pattern, a Route is passed to the handler.
The handler must call one of fulfill(), continue_(), abort(), or fallback()
to resolve the request.
Implementations§
Source§impl Route
impl Route
Sourcepub async fn is_handled(&self) -> bool
pub async fn is_handled(&self) -> bool
Check if this route has been handled.
Sourcepub fn is_response_stage(&self) -> bool
pub fn is_response_stage(&self) -> bool
Check if this route is at the response stage.
Sourcepub fn response_status(&self) -> Option<u16>
pub fn response_status(&self) -> Option<u16>
Get the response status code (if at response stage).
Sourcepub fn response_headers(&self) -> Option<&[HeaderEntry]>
pub fn response_headers(&self) -> Option<&[HeaderEntry]>
Get the response headers (if at response stage).
Sourcepub async fn response_body(&self) -> Result<Option<Vec<u8>>, NetworkError>
pub async fn response_body(&self) -> Result<Option<Vec<u8>>, NetworkError>
Get the response body (if at response stage).
§Errors
Returns an error if not at response stage or body cannot be fetched.
Sourcepub fn fulfill(&self) -> FulfillBuilder<'_>
pub fn fulfill(&self) -> FulfillBuilder<'_>
Fulfill the request with a custom response.
§Example
use viewpoint_core::Route;
route.fulfill()
.status(200)
.content_type("application/json")
.body(r#"{"success": true}"#)
.send()
.await?;Sourcepub fn continue_(&self) -> ContinueBuilder<'_>
pub fn continue_(&self) -> ContinueBuilder<'_>
Continue the request with optional modifications.
§Example
use viewpoint_core::Route;
// Continue unchanged
route.continue_().send().await?;
// Modify the request
route.continue_()
.header("X-Custom", "value")
.send()
.await?;Sourcepub async fn abort(&self) -> Result<(), NetworkError>
pub async fn abort(&self) -> Result<(), NetworkError>
Sourcepub async fn abort_with(&self, error: AbortError) -> Result<(), NetworkError>
pub async fn abort_with(&self, error: AbortError) -> Result<(), NetworkError>
Sourcepub async fn fallback(&self) -> Result<(), NetworkError>
pub async fn fallback(&self) -> Result<(), NetworkError>
Pass this request to the next matching route handler.
If no other handlers match, the request continues to the server.
§Errors
Returns an error if the fallback fails.
Sourcepub fn fetch(&self) -> FetchBuilder<'_>
pub fn fetch(&self) -> FetchBuilder<'_>
Fetch the actual response from the server, allowing inspection/modification.
§Example
use viewpoint_core::Route;
let response = route.fetch().send().await?;
println!("Status: {}", response.status);
// Modify and send to page
route.fulfill()
.response(&response)
.header("X-Modified", "true")
.send()
.await?;Sourcepub async fn fetch_with_timeout(
&self,
timeout: Duration,
) -> Result<FetchedResponse<'_>, NetworkError>
pub async fn fetch_with_timeout( &self, timeout: Duration, ) -> Result<FetchedResponse<'_>, NetworkError>
Fetch the response with a timeout.