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.