pub struct SessionManager { /* private fields */ }Expand description
Manages named sessions and dispatches fetch requests to the appropriate one.
The engine owns a single SessionManager and uses it for every fetch during
the crawl. Sessions are identified by string IDs; one session is designated
as the default and is used whenever a Request
does not specify a sid.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty session manager with no sessions registered. You must
call add at least once before the engine can
fetch anything; the engine will return an error if the manager is empty.
Sourcepub fn add(
&mut self,
session_id: impl Into<String>,
session: Session,
default: bool,
) -> Result<()>
pub fn add( &mut self, session_id: impl Into<String>, session: Session, default: bool, ) -> Result<()>
Registers a session under the given ID, optionally marking it as the
default. The first session added automatically becomes the default even
if default is false. Returns an error if a session with the same ID
already exists.
Sourcepub fn default_session_id(&self) -> Result<&str>
pub fn default_session_id(&self) -> Result<&str>
Returns the default session ID, or an error if none is set. The engine
calls this whenever a request has an empty sid field to determine which
session to use.
Sourcepub fn session_ids(&self) -> Vec<&str>
pub fn session_ids(&self) -> Vec<&str>
Returns a list of all registered session IDs.
Sourcepub fn get(&self, session_id: &str) -> Result<&Session>
pub fn get(&self, session_id: &str) -> Result<&Session>
Returns a reference to the session with the given ID, or an error if not found.
Sourcepub fn get_mut(&mut self, session_id: &str) -> Result<&mut Session>
pub fn get_mut(&mut self, session_id: &str) -> Result<&mut Session>
Returns a mutable reference to the session with the given ID, or an error if not found.
Sourcepub async fn fetch(&self, request: &Request) -> Result<Response>
pub async fn fetch(&self, request: &Request) -> Result<Response>
Fetches the URL from the request using the appropriate session.
If the request has a non-empty sid, that session is used; otherwise
the default session is selected. The method dispatches to the correct
get implementation depending on whether the session is a Fetcher
or a FetcherSession. Returns the HTTP response on success, or a
SpiderError on failure.