Skip to main content

Session

Struct Session 

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

Cookie, score, and user-data state associated with a crawling identity.

use millipede_core::session::{Session, SessionConfig};
let session = Session::new(SessionConfig::default());
assert!(session.id().as_str().starts_with("session-"));

Implementations§

Source§

impl Session

Source

pub fn new(config: SessionConfig) -> Self

Creates an empty session with a generated identifier.

Source

pub fn id(&self) -> &SessionId

Returns this session’s identifier.

Source

pub fn cookie_jar(&self) -> &Arc<CookieJar>

Returns the authoritative shared cookie jar.

Source

pub async fn with_user_data<R>(&self, f: impl FnOnce(&UserData) -> R) -> R

Reads user data through a synchronous closure, releasing the lock on return.

Source

pub async fn update_user_data(&self, f: impl FnOnce(&mut UserData))

Mutates user data through a synchronous closure, releasing the lock on return.

Source

pub async fn error_score(&self) -> f32

Returns the error score in unscaled units.

Source

pub async fn usage_count(&self) -> u32

Returns the number of attempts served.

Source

pub async fn record_usage(&self)

Records one checkout attempt. Session pools call this when serving a session.

Source

pub async fn is_blocked(&self) -> bool

Returns whether the error threshold has been reached.

Source

pub fn is_expired(&self) -> bool

Returns whether the fixed creation-time expiry has passed.

Source

pub async fn is_retired(&self) -> bool

Returns whether the session was explicitly retired.

Source

pub async fn is_usable(&self) -> bool

Returns whether the session can serve another attempt.

Source

pub async fn mark_good(&self)

Decreases the error score, flooring it at zero.

Source

pub async fn mark_bad(&self)

Adds one scaled error point, saturating at u32::MAX.

Source

pub async fn retire(&self)

Permanently retires this session.

Source

pub fn set_cookies_from_response(&self, response: &HttpResponse)

Stores Set-Cookie headers synchronously and infallibly.

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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, 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<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