Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

Request represents an HTTP request during navigation.

Request objects are created by the server during navigation operations. They are parents to Response objects.

See: https://playwright.dev/docs/api/class-request

Implementations§

Source§

impl Request

Source

pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>

Creates a new Request from protocol initialization

This is called by the object factory when the server sends a __create__ message for a Request object.

Source

pub fn frame(&self) -> Option<Frame>

Returns the Frame that initiated this request.

The frame is resolved from the frame GUID in the protocol initializer data.

See: https://playwright.dev/docs/api/class-request#request-frame

Source

pub fn redirected_from(&self) -> Option<Request>

Returns the request that redirected to this one, or None.

When the server responds with a redirect, Playwright creates a new Request for the redirect target. The new request’s redirected_from points back to the original request.

See: https://playwright.dev/docs/api/class-request#request-redirected-from

Source

pub fn redirected_to(&self) -> Option<Request>

Returns the request that this one redirected to, or None.

This is the inverse of redirected_from(): if request A redirected to request B, then A.redirected_to() returns B.

See: https://playwright.dev/docs/api/class-request#request-redirected-to

Source

pub fn existing_response(&self) -> Option<Response>

Returns the Response if it has already been received, or None if the response has not yet arrived.

This method returns immediately without waiting. Use response() if you need to wait for the response to arrive.

See: https://playwright.dev/docs/api/class-request#request-existing-response

Source

pub async fn response(&self) -> Result<Option<Response>>

Returns the Response for this request.

Sends a "response" RPC call to the Playwright server. Returns None if the request has not received a response (e.g., it failed).

See: https://playwright.dev/docs/api/class-request#request-response

Source

pub async fn sizes(&self) -> Result<RequestSizes>

Returns resource size information for this request.

Internally fetches the associated Response (via RPC) and calls sizes() on the response’s channel.

See: https://playwright.dev/docs/api/class-request#request-sizes

Source

pub fn url(&self) -> &str

Returns the URL of the request.

See: https://playwright.dev/docs/api/class-request#request-url

Source

pub fn method(&self) -> &str

Returns the HTTP method of the request (GET, POST, etc.).

See: https://playwright.dev/docs/api/class-request#request-method

Source

pub fn resource_type(&self) -> &str

Returns the resource type of the request (e.g., “document”, “stylesheet”, “image”, “fetch”, etc.).

See: https://playwright.dev/docs/api/class-request#request-resource-type

Source

pub fn is_navigation_request(&self) -> bool

Check if this request is for a navigation (main document).

A navigation request is when the request is for the main frame’s document. This is used to distinguish between main document loads and subresource loads.

See: https://playwright.dev/docs/api/class-request#request-is-navigation-request

Source

pub fn headers(&self) -> HashMap<String, String>

Returns the request headers as a HashMap.

The headers are read from the protocol initializer data. The format in the protocol is a list of {name, value} objects which are merged into a HashMap<String, String>. If duplicate header names exist, the last value wins.

For the full set of raw headers (including duplicates), use headers_array() or all_headers().

See: https://playwright.dev/docs/api/class-request#request-headers

Source

pub fn post_data_buffer(&self) -> Option<Vec<u8>>

Returns the request body (POST data) as bytes, or None if there is no body.

The Playwright protocol sends postData as a base64-encoded string. This method decodes it to raw bytes.

This is a local read and does not require an RPC call.

See: https://playwright.dev/docs/api/class-request#request-post-data-buffer

Source

pub fn post_data(&self) -> Option<String>

Returns the request body (POST data) as a UTF-8 string, or None if there is no body.

The Playwright protocol sends postData as a base64-encoded string. This method decodes the base64 and then converts the bytes to a UTF-8 string.

This is a local read and does not require an RPC call.

See: https://playwright.dev/docs/api/class-request#request-post-data

Source

pub fn post_data_json<T: DeserializeOwned>(&self) -> Option<Result<T>>

Parses the POST data as JSON and deserializes into the target type T.

Returns None if the request has no POST data, or Some(Err(...)) if the JSON parsing fails.

See: https://playwright.dev/docs/api/class-request#request-post-data-json

Source

pub fn failure(&self) -> Option<String>

Returns the error text if the request failed, or None for successful requests.

The failure text is set when the requestFailed browser event fires for this request. Use page.on_request_failed() to capture failed requests and then call this method to get the error reason.

See: https://playwright.dev/docs/api/class-request#request-failure

Source

pub async fn headers_array(&self) -> Result<Vec<HeaderEntry>>

Returns all request headers as name-value pairs, preserving duplicates.

Sends a "rawRequestHeaders" RPC call to the Playwright server which returns the complete list of headers as sent over the wire, including headers added by the browser (e.g., accept-encoding, accept-language).

§Errors

Returns an error if the RPC call to the server fails.

See: https://playwright.dev/docs/api/class-request#request-headers-array

Source

pub async fn all_headers(&self) -> Result<HashMap<String, String>>

Returns all request headers as a HashMap<String, String> with lowercased keys.

When multiple headers have the same name, their values are joined with \n (matching Playwright’s behavior).

Sends a "rawRequestHeaders" RPC call to the Playwright server.

§Errors

Returns an error if the RPC call to the server fails.

See: https://playwright.dev/docs/api/class-request#request-all-headers

Source

pub async fn header_value(&self, name: &str) -> Result<Option<String>>

Returns the value of the specified header (case-insensitive), or None if not found.

Uses all_headers() internally, so it sends a "rawRequestHeaders" RPC call to the Playwright server.

§Errors

Returns an error if the RPC call to the server fails.

See: https://playwright.dev/docs/api/class-request#request-header-value

Source

pub async fn timing(&self) -> Result<ResourceTiming>

Returns timing information for the request.

The timing data is sourced from the associated Response’s initializer when the requestFinished event fires. This method should be called from within a page.on_request_finished() handler or after it has fired.

Fields use -1 to indicate that a timing phase was not reached or is unavailable for a given request.

§Errors

Returns an error if timing data is not yet available (e.g., called before requestFinished fires, or for a request that has not completed successfully).

See: https://playwright.dev/docs/api/class-request#request-timing

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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