pub struct PausedRequest {
pub request_id: String,
pub request: RequestInfo,
pub response: Option<ResponseInfo>,
/* private fields */
}interception only.Expand description
Network interception API re-exports.
Gated by the interception cargo feature. The full surface lives in the
zendriver-interception sub-crate; these aliases let downstream code
reach the types without depending on the sub-crate directly.
A request paused by Chrome at the configured RequestStage.
PausedRequest is consumed by exactly one of the action methods
(continue_, abort,
respond,
modify_and_continue,
continue_response) to release the pause.
body is a read-only side-channel (&self) usable at the
Response stage to inspect the upstream body before deciding which
terminal action to take.
If a PausedRequest is dropped without one of the terminal actions
firing (e.g. the consuming task panicked or a select! arm cancelled
mid-handler), Drop dispatches a best-effort Fetch.continueRequest
in a detached task so Chrome doesn’t hold the request open indefinitely.
See cdpdriver/zendriver#126 for the freeze pattern this prevents.
Fields§
§request_id: StringOpaque CDP request id (requestId on Fetch.requestPaused). Must be
echoed back on whichever terminal action releases the pause.
request: RequestInfoDecoded request payload as Chrome surfaced it.
response: Option<ResponseInfo>Decoded response payload — populated only when Chrome paused at the
Response stage. None at the Request stage.
Implementations§
Source§impl PausedRequest
impl PausedRequest
Sourcepub async fn continue_(self) -> Result<(), InterceptionError>
pub async fn continue_(self) -> Result<(), InterceptionError>
Release the pause and let Chrome send the request as-is.
Dispatches Fetch.continueRequest { requestId } with no overrides.
Use modify_and_continue instead if any
field needs to be rewritten.
use zendriver_interception::InterceptBuilder;
let mut stream = Box::pin(InterceptBuilder::new(tab).subscribe());
while let Some(req) = stream.next().await {
req.continue_().await?;
}Sourcepub async fn abort(self, reason: AbortReason) -> Result<(), InterceptionError>
pub async fn abort(self, reason: AbortReason) -> Result<(), InterceptionError>
Abort the request with the given Chrome Network.ErrorReason.
Dispatches Fetch.failRequest { requestId, errorReason }. The exact
reason surfaces to JS as the rejected fetch() / XHR error.
use zendriver_interception::{AbortReason, InterceptBuilder};
let mut stream = Box::pin(InterceptBuilder::new(tab).subscribe());
if let Some(req) = stream.next().await {
req.abort(AbortReason::BlockedByClient).await?;
}Sourcepub async fn respond(
self,
status: u16,
headers: Vec<(String, String)>,
body: Vec<u8>,
) -> Result<(), InterceptionError>
pub async fn respond( self, status: u16, headers: Vec<(String, String)>, body: Vec<u8>, ) -> Result<(), InterceptionError>
Synthesize a response and serve it in place of the upstream one.
Dispatches Fetch.fulfillRequest { requestId, responseCode, responseHeaders: [{name, value}, ...], body: base64(body) }. Headers
are CDP’s name/value array form; body is base64-encoded on the wire
per CDP spec (callers pass raw bytes).
Sourcepub async fn modify_and_continue(
self,
overrides: RequestOverrides,
) -> Result<(), InterceptionError>
pub async fn modify_and_continue( self, overrides: RequestOverrides, ) -> Result<(), InterceptionError>
Release the pause with per-field overrides applied.
Dispatches Fetch.continueRequest { requestId, url?, method?, headers?, postData? }. Only fields set on RequestOverrides are forwarded —
None leaves Chrome’s original value untouched. Per CDP, postData
crosses the wire base64-encoded and headers is the CDP name/value
array form (replacement, not merge).
Sourcepub async fn continue_response(
self,
status: Option<u16>,
phrase: Option<String>,
headers: Option<Vec<(String, String)>>,
) -> Result<(), InterceptionError>
pub async fn continue_response( self, status: Option<u16>, phrase: Option<String>, headers: Option<Vec<(String, String)>>, ) -> Result<(), InterceptionError>
Forward the upstream response, optionally rewriting its status and/or headers, while keeping Chrome’s original body.
Only valid at the Response stage — Chrome only accepts
Fetch.continueResponse once the upstream response headers have
arrived. Called on a Request-stage PausedRequest (where
response is None), it returns
InterceptionError::WrongStage without dispatching anything; use
respond to serve a synthetic response at the
Request stage instead.
Dispatches Fetch.continueResponse { requestId, responseCode?, responsePhrase?, responseHeaders? }, omitting any argument left None
so Chrome keeps its original value. Per CDP, responseHeaders is the
name/value array form and is replacement, not merge — pass every
header you want forwarded.
use zendriver_interception::InterceptBuilder;
let mut stream = Box::pin(
InterceptBuilder::new(tab).pattern("*").at_response().subscribe(),
);
if let Some(req) = stream.next().await {
// Rewrite to 204 No Content, keep the upstream body.
req.continue_response(Some(204), None, None).await?;
}Sourcepub async fn body(&self) -> Result<Vec<u8>, InterceptionError>
pub async fn body(&self) -> Result<Vec<u8>, InterceptionError>
Fetch the upstream response body. Only useful at the Response
stage — at the Request stage Chrome has no body to return.
Dispatches Fetch.getResponseBody { requestId }. Per CDP the result
carries a body string plus a base64Encoded: bool flag: when true,
we base64-decode; when false, we return the UTF-8 bytes verbatim. Keeps
&self (not self) so callers can inspect-then-decide.
Trait Implementations§
Source§impl Debug for PausedRequest
impl Debug for PausedRequest
Source§impl Drop for PausedRequest
Safety net for cdpdriver/zendriver#126: a paused request that gets dropped
without a terminal action (panicked handler, cancelled select! arm,
stream consumer exited early) would otherwise leave Chrome waiting on
requestId forever and freeze the whole client. Spawning a detached
Fetch.continueRequest releases the pause best-effort; failures are
logged at debug! because the session may already be torn down (e.g. tab
closed mid-pause), which is the same condition that produced the original
freeze and not an actionable error.
impl Drop for PausedRequest
Safety net for cdpdriver/zendriver#126: a paused request that gets dropped
without a terminal action (panicked handler, cancelled select! arm,
stream consumer exited early) would otherwise leave Chrome waiting on
requestId forever and freeze the whole client. Spawning a detached
Fetch.continueRequest releases the pause best-effort; failures are
logged at debug! because the session may already be torn down (e.g. tab
closed mid-pause), which is the same condition that produced the original
freeze and not an actionable error.