Skip to main content

PausedRequest

Struct PausedRequest 

Source
pub struct PausedRequest {
    pub request_id: String,
    pub request: RequestInfo,
    pub response: Option<ResponseInfo>,
    /* private fields */
}
Available on crate feature 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: String

Opaque CDP request id (requestId on Fetch.requestPaused). Must be echoed back on whichever terminal action releases the pause.

§request: RequestInfo

Decoded 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

Source

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?;
}
Source

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?;
}
Source

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).

Source

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).

Source

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?;
}
Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
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.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more