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
impl FetcherSession
Sourcepub fn new(config: FetcherConfig) -> Self
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.
Sourcepub fn with_rotator(self, rotator: ProxyRotator) -> Self
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.
Sourcepub fn with_parser_config(self, parser_config: ParserConfig) -> Self
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.
Sourcepub fn close(&mut self)
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().
Sourcepub async fn get(
&self,
url: &str,
req: Option<RequestConfig>,
) -> Result<Response>
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.
Sourcepub async fn post(
&self,
url: &str,
req: Option<RequestConfig>,
) -> Result<Response>
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.
Sourcepub async fn put(
&self,
url: &str,
req: Option<RequestConfig>,
) -> Result<Response>
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FetcherSession
impl !RefUnwindSafe for FetcherSession
impl Send for FetcherSession
impl Sync for FetcherSession
impl Unpin for FetcherSession
impl UnsafeUnpin for FetcherSession
impl !UnwindSafe for FetcherSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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