Skip to main content

leyline/core/session/
mod.rs

1#![forbid(unsafe_code)]
2mod builder;
3pub(crate) mod decompress;
4pub(crate) mod execute;
5mod header_merge;
6mod helpers;
7mod identity;
8mod proxy;
9mod transport_policy;
10#[cfg(feature = "websocket")]
11mod websocket;
12
13#[cfg(test)]
14mod tests;
15
16pub use builder::SessionBuilder;
17pub use identity::{Identity, SessionIdentity};
18#[cfg(feature = "websocket")]
19pub use websocket::WebSocketBuilder;
20
21use std::sync::{Arc, Mutex};
22
23use url::Url;
24
25use crate::cookie::Jar;
26#[cfg(feature = "websocket")]
27use crate::core::WebSocketConfig;
28use crate::core::retry::RetryPolicy;
29use crate::core::{CompressionConfig, ProxyConfig, RedirectPolicy, TimeoutConfig};
30use crate::h2::H2Config;
31use crate::pool::Pool;
32use crate::profile::{Browser, ChromiumBrand, HeaderStyle, Platform};
33use crate::tls::FingerprintConnector;
34#[cfg(feature = "http3")]
35use crate::tls::TlsTrustConfig;
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38#[non_exhaustive]
39pub enum ProtocolPolicy {
40    Auto,
41    Http1,
42    Http2,
43    #[cfg(feature = "http3")]
44    Http3,
45    #[cfg(feature = "http3")]
46    Race,
47}
48
49impl ProtocolPolicy {
50    #[cfg(feature = "http3")]
51    pub(crate) fn requires_h3(self) -> bool {
52        matches!(self, Self::Http3 | Self::Race)
53    }
54}
55
56#[derive(Clone)]
57pub struct Session {
58    inner: Arc<SessionInner>,
59}
60
61#[derive(Clone)]
62pub(crate) struct SessionInner {
63    browser: Option<Browser>,
64    impersonates: bool,
65    header_style: HeaderStyle,
66    identity: Option<Identity>,
67    platform: Platform,
68    brand: ChromiumBrand,
69    user_agent: String,
70    sec_ch_ua: String,
71    accept_language: String,
72    header_order: Option<Vec<String>>,
73    default_headers: Vec<(String, String)>,
74    proxy_config: ProxyConfig,
75    timeouts: TimeoutConfig,
76    redirect_policy: RedirectPolicy,
77    compression: CompressionConfig,
78    #[cfg(feature = "websocket")]
79    websocket_config: WebSocketConfig,
80    https_only: bool,
81    cookie_jar: Jar,
82    connector: FingerprintConnector,
83    h2_config: H2Config,
84    pool: Arc<Pool>,
85    audit_tls: Option<Arc<crate::audit::AuditTlsCache>>,
86    protocol_policy: ProtocolPolicy,
87    default_retry: RetryPolicy,
88    #[cfg(feature = "http3")]
89    h3_config: Option<crate::quic::H3Config>,
90    #[cfg(feature = "http3")]
91    tls_trust: TlsTrustConfig,
92    profile: Arc<crate::profile::BrowserProfile>,
93    trace: Option<Arc<dyn crate::trace::Trace>>,
94    #[expect(
95        clippy::type_complexity,
96        reason = "The shared cache retains raw input and a parsed URL shared by active requests"
97    )]
98    url_cache: Arc<Mutex<Option<(String, Arc<Url>)>>>,
99}