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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
impl !UnwindSafe for SessionManager
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