Skip to main content

FetcherSession

Struct FetcherSession 

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

Session-based async HTTP fetcher that reuses a persistent client with cookie storage.

Unlike Fetcher, this struct maintains a single wreq client across requests, which means cookies set by one response are automatically sent with subsequent requests. This is essential for login flows, CSRF-protected forms, and any multi-step interaction where server-side session state matters.

Lifecycle: create with new(), call open() to start the session, make requests, then call close() (or just drop it).

Implementations§

Source§

impl FetcherSession

Source

pub fn new(config: FetcherConfig) -> Self

Creates a new session with the given configuration. The session is not yet active – you must call open() before making requests.

Source

pub fn with_rotator(self, rotator: ProxyRotator) -> Self

Attaches a proxy rotator to the session. Must be called before open() since the proxy is configured on the underlying client.

Source

pub fn with_parser_config(self, parser_config: ParserConfig) -> Self

Sets the parser configuration for the session. Controls how responses from this session parse and interpret HTML.

Source

pub fn open(&mut self) -> Result<()>

Opens the session by creating the underlying HTTP client with a cookie store. Returns an error if the session is already active. After this call, you can make requests with get(), post(), etc.

Source

pub fn close(&mut self)

Closes the session and drops the underlying HTTP client. All cookies and connection state are discarded. The session can be re-opened with open().

Source

pub fn is_active(&self) -> bool

Returns true if the session is currently active (i.e., open() has been called and close() has not).

Source

pub async fn get( &self, url: &str, req: Option<RequestConfig>, ) -> Result<Response>

Sends an HTTP GET request using the session client. Cookies from prior responses are automatically included. Returns an error if the session is not active.

Source

pub async fn post( &self, url: &str, req: Option<RequestConfig>, ) -> Result<Response>

Sends an HTTP POST request using the session client. Use RequestConfig::json or RequestConfig::data to attach a body.

Source

pub async fn put( &self, url: &str, req: Option<RequestConfig>, ) -> Result<Response>

Sends an HTTP PUT request using the session client. Use RequestConfig::json or RequestConfig::data to attach a body.

Source

pub async fn delete( &self, url: &str, req: Option<RequestConfig>, ) -> Result<Response>

Sends an HTTP DELETE request using the session client.

Trait Implementations§

Source§

impl Drop for FetcherSession

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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